[ACCEPTED]-How can I find out why subprocess.Popen wait() waits forever if stdout=PIPE?-subprocess

Accepted answer
Score: 51

When a pipe's buffer fills up (typically 14 4KB or so), the writing process stops until 13 a reading process has read some of the data 12 in question; but here you're reading nothing 11 until the subprocess is done, hence the 10 deadlock. The docs on wait put it very clearly indeed:

Warning This 9 will deadlock if the child process generates 8 enough output to a stdout or stderr pipe 7 such that it blocks waiting for the OS 6 pipe buffer to accept more data. Use communicate() to 5 avoid that.

If you can't use communicate for some reason, have 4 the subprocess write to a temporary file, and 3 then you can wait and read that file when it's 2 ready -- writing to a file, instead of to 1 a pipe, does not risk deadlock.

Score: 3

Take a look at the docs. It states that you 2 shouldn't use wait as it can cause a dead 1 lock. Try using communicate.

More Related questions