os.wait() losing child?

Hrvoje Niksic hniksic at xemacs.org
Thu Jul 12 22:39:41 CEST 2007

Nick Craig-Wood <nick at craig-wood.com> writes:

>>  This can still be a problem for applications that call wait in a
>>  dedicated thread, but the program can always ignore the processes
>>  it doesn't know anything about.
> Ignoring them isn't good enough because it means that the bit of
> code which was waiting for that process to die with os.getpid() will
> never get called, causing a deadlock in that bit of code.

It won't deadlock, it will get an ECHILD or equivalent error because
it's waiting for a PID that doesn't correspond to a running child
process.  I agree that this can be a problem if and when you use
libraries that can call system.  (In that case sleeping for SIGCHLD is
probably a good solution.)

> What is really required is a select() like interface to wait which
> takes more than one pid.  I don't think there is such a thing
> though, so polling is your next best option.

Except for the problems outlined in my previous message.  And the fact
that polling becomes very expensive (O(n) per check) once the number
of processes becomes large.  Unless one knows that a library can and
does call system, wait is the preferred solution.

More information about the Python-list mailing list