xolox/python-executor

no blocking communicate pipe

arita37 opened this issue · 1 comments

how to read the output of stdout
for asynchronous procees without blocking the process ?

xolox commented

Hi @arita37 and sorry for not replying earlier. I'm not sure whether I can provide a satisfactory response to your question, but I'll do my best by pointing in several directions:

  • The ExternalCommand.buffered property documentation contains an example that processes the output of the xscreensaver-command -watch command in realtime. This does involve blocking, but it may be sufficient for your purposes?
  • If standard output is being buffered to a temporary file then it becomes trivial to access what has already been written on the standard output stream without blocking the parent process, however this makes it impossible to deal with an unbounded output size.
  • If you need to support an unbounded output size you will need to pass capture=True and buffered=False. Once the process has been started you can use the ExternalCommand.stdout property to get access to the underlying file-like object. At this point there are many ways to perform or simulate non-blocking reads from pipes, which you choose depends on your situation.

I hope one of these suggestions helps.