Bug in popen2.Popen3?

Jeffrey Barish jeffbarish at starband.net
Wed Jun 16 12:43:07 EDT 2004


Popen3 provides the method poll() which returns the exit status of the
child process if it has finished or -1 if the process is still running. 
Here is the code:

def poll(self):
    """Return the exit status of the child process if it has finished,
    or -1 if it hasn't finished yet."""
    if self.sts < 0:
        try:
            pid, sts = os.waitpid(self.pid, os.WNOHANG)
            if pid == self.pid:
                self.sts = sts
                _active.remove(self)
        except os.error:
            pass
    return self.sts

If the child process has already exited when poll() is first called, the
os.waitpid will raise an exception (No child process).  The exception
is caught and poll() returns self.sts, which is -1.  There is no way
for the value of self.sts to change from -1.
-- 
Jeffrey Barish





More information about the Python-list mailing list