469,288 Members | 2,353 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,288 developers. It's quick & easy.

Bug in popen2.Popen3?

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
Jul 18 '05 #1
1 2483
In article <ma***********************************@python.org> ,
Jeffrey Barish <je********@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, do**@u.washington.edu
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by A. Lloyd Flanagan | last post: by
1 post views Thread by | last post: by
4 posts views Thread by P | last post: by
4 posts views Thread by Rembrandt Q Einstein | last post: by
1 post views Thread by lists04 | last post: by
3 posts views Thread by alexrait1 | last post: by
11 posts views Thread by g.franzkowiak | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.