popen2.Popen3 and slightly large output

Jeff Epler jepler at unpythonic.net
Thu Aug 15 14:51:34 EDT 2002


Popen3.poll() checks whether the child process has exited.
The child process won't exit until its input has been read or the pipe
has been closed.  Its write()s will be blocking writes.

If you want to find out whether there is some amount of input available,
use select on .fromchild:
    def readable(fd):
	return bool(select.select([fd], [], [], 0))

    if readable(x.fromchild):
	read some output

Imagine that the process you started in "x" will create, say, 300GB of
data.  How do you expect all that data to be produced and stored in the
meantime?  On good old DOS, this data was written to a temporary file,
but that solution was a hack for a non-multitasking environment.  My
relatively old 350MHz machine can produce 300GB of zeroes in about 20
seconds, according to
    time dd if=/dev/zero of=/dev/null bs=1048576 count=300000
so it's clear that computers can produce bigger-than-disk (let alone
bigger-than-RAM) outpus fairly easily.

Your smaller program happens to allow all output to fit in the pipe
buffer, and when the child has written its output it will exit and you
can get your value from poll().

Jeff




More information about the Python-list mailing list