popen2.Popen4: "wait()" hangs on

Christopher T King squirrel at WPI.EDU
Mon Jul 26 15:17:48 CEST 2004


On Mon, 26 Jul 2004, Vivien Mallet wrote:

> "f.wait()" doesn't return anything. It just hangs on. "f.poll()" returns -1
> all the time, even if "lines 50000" should end within one or two seconds.
>
> My guess is that too many characters are sent to the standard output. I
> found a way to deal with this problem:

Your diagnosis is nearly correct.  The actual reason is that "lines" is
trying to write output, but since nothing is consuming the output, it is
forced to block on its 'print' statements.  Because f.wait() is waiting
for "lines" to finish, it will keep blocking until "lines" is able to
write its output somewhere.

The solutions you give are quite correct;  they consume the output before
waiting for the process to complete (I might also suggest using select()
in place of .poll(), though).  What is it you're actually trying to 
accomplish, though?  If you're just trying to run a process in parallel, 
but ignore its output, one of the spawn() family of calls might work 
better (these will send the output to the same place as your main 
program).  If you want to discard the output entirely, then you can use a 
combination of fork() and one of the exec() calls, redirecting sys.stdout 
to /dev/null in the process.

Hope this helps.




More information about the Python-list mailing list