0

Following: live output from subprocess command.

I would like to run a process with subprocess.Popen() and get both live STDOUT and STDERR. The problem is that if I do readline on one of them, it will block, and I won't be able to readline the other. I also don't want to unite them to one PIPE.

Is there a simple way to do it without using 2 threads per process?

Elad Weiss
  • 3,662
  • 3
  • 22
  • 50
  • 1
    Did you see [this answer](https://stackoverflow.com/a/18423003/2415524)? There is a description of what to do when you need two or more pipes and how to avoid deadlock. There is also a [comment](https://stackoverflow.com/questions/18421757/live-output-from-subprocess-command#comment40948811_18423003) on this answer that links to "concrete code examples". [This](https://stackoverflow.com/a/25755038/2415524) is probably the most relevant example...? – mbomb007 Jan 11 '18 at 15:15
  • 1
    After a brief look at the linked examples, I think it has to be multiple threads per process. If I understand correctly, you want two live IO streams, so you have to consume them both asynchronously to avoid deadlock. – mbomb007 Jan 11 '18 at 15:23
  • @mbomb007 Thanks. I'll read that answer and the links. – Elad Weiss Jan 11 '18 at 15:27

0 Answers0