Re:It's all fun and games until someone [XOFF]
by pjungwir on Monday June 22, 2015 @03:04PM
(#9760481)
Yep, I've hit this in Perl and Ruby and even once wrote a class to do something like Python's `communicate`. It's especially trappy if you want to run a command and both send stuff to its stdin and read stuff from its stdout. Bash makes it so easy, but it's a fraught with danger anywhere else!
I imagine your broken code did something like:
To avoid the deadlock, it is enough to swap the last two statements: that you would normally write as: If you need to consume more than one pipe separately then you should consume them concurrently and therefore you need threads or async.io.`Popen.communicate()` can read from both pipes concurrently (as you've mentioned) and it is always available. It was available even in Python 2.4 that introduced the subprocess module.