os.wait() losing child?

Jason Zheng Xin.Zheng at jpl.nasa.gov
Wed Jul 11 20:24:33 CEST 2007


greg wrote:
> Jason Zheng wrote:
>> Hate to reply to my own thread, but this is the working program that 
>> can demonstrate what I posted earlier:
> 
> I've figured out what's going on. The Popen class has a
> __del__ method which does a non-blocking wait of its own.
> So you need to keep the Popen instance for each subprocess
> alive until your wait call has cleaned it up.
> 
> The following version seems to work okay.
> 
It still doesn't work on my machine. I took a closer look at the Popen 
class, and I think the problem is that the __init__ method always calls 
a method _cleanup, which polls every existing Popen instance. The poll 
method does a nonblocking wait.

If one of my child process finishes as I create a new Popen instance, 
then the _cleanup method effectively de-zombifies the child process, so 
I can no longer expect to see the return of that pid on os.wait() any more.

~Jason



More information about the Python-list mailing list