subprocess module and blocking

Robin Becker robin at
Sun Jun 12 11:22:52 CEST 2005

I'm using a polling loop in a thread that looks approximately like this

while 1:
     p = find_a_process()
     rc = p.poll()
     if rc is not None:
         out, err = p.communicate()
         #deal with output etc

the process p is opened using

p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=cwd)

stdin is actually never written to.

I notice that under both win32 and freebsd that things are fine provided 
that the subprocess doesn't write too much to stdout/stderr. However, 
the subprocess seems to lock often if too much is written (under freebsd 
I see a process state of POLL). I assume that the subprocess is filling 
up the pipe and then failing to wake up again. I had expected that 
subprocess would take care of this for me, but possibly I'm being 
utterly clueless and stupid. What should I do to avoid blocking in the 
Robin Becker

More information about the Python-list mailing list