os.wait() losing child?

Nick Craig-Wood nick at craig-wood.com
Thu Jul 12 12:30:04 CEST 2007

Jason Zheng <Xin.Zheng at jpl.nasa.gov> wrote:
>  Nick Craig-Wood wrote:
> > The problem you are having is you are letting Popen do half the job
> > and doing the other half yourself.
>  Except that I never wanted Popen to do any thread management for me to 
>  begin with. Popen class has advertised itself as a replacement for 
>  os.popen, popen2, popen4, and etc., and IMHO it should leave the 
>  clean-up to the users, or at least leave it as an option.
> > Here is a way which works, done completely with Popen.  Polling the
> > subprocesses is slightly less efficient than using os.wait() but does
> > work.  In practice you want to do this anyway to see if your children
> > exceed their time limits etc.
>  I think your polling way works; it seems there no other way around this 
>  problem other than polling or extending Popen class.

I think polling is probably the right way of doing it...

Internally subprocess uses os.waitpid(pid) just waiting for its own
specific pids.  IMHO this is the right way of doing it other than
os.wait() which waits for any pids.  os.wait() can reap children that
you weren't expecting (say some library uses os.system())...

Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick

More information about the Python-list mailing list