Bug in popen2.Popen3?

Donn Cave donn at u.washington.edu
Thu Jun 17 12:42:26 EDT 2004


In article <mailman.12.1087470200.739.python-list at python.org>,
 Jeffrey Barish <jeffbarish at starband.net> wrote:

> 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.

No child process happens when the (last) child has exited
_and_ its status is no longer available.  Why no longer
available?  Maybe someone's stealing it - another wait()
call somewhere in the process.  Maybe someone's setting
SIGCHLD to SIG_IGN, or whatever that wretched gimmick is
that on some platforms causes exit status to be discarded
immediately.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list