Bug in popen2.Popen3?

J

Jeffrey Barish

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

Donn Cave

Jeffrey Barish said:
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, (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top