Bug in popen2.Popen3?

Discussion in 'Python' started by Jeffrey Barish, Jun 16, 2004.

  1. 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
     
    Jeffrey Barish, Jun 16, 2004
    #1
    1. Advertising

  2. Jeffrey Barish

    Donn Cave Guest

    In article <>,
    Jeffrey Barish <> 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 Cave, Jun 17, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guy

    popen2

    Guy, Aug 12, 2003, in forum: Python
    Replies:
    1
    Views:
    2,856
    Donn Cave
    Aug 12, 2003
  2. cherico

    popen2 with large input

    cherico, Jan 29, 2004, in forum: Python
    Replies:
    2
    Views:
    333
    Jeff Epler
    Jan 29, 2004
  3. Guest
    Replies:
    1
    Views:
    483
    Donn Cave
    Jun 15, 2004
  4. alexrait1
    Replies:
    3
    Views:
    468
    Steven Bethard
    Mar 9, 2005
  5. Replies:
    1
    Views:
    434
    Fredrik Lundh
    Jun 7, 2006
Loading...

Share This Page