The subprocess module automatically reaps child processes, by
maintaining a list of instances which is traversed each time a new
Popen instance is created.
Apparently this was originally intended to avoid large number of
zombie processes to accrete in the system if the programmer is
lazy and does not wait for them properly, but it can cause problems
when the programmer wants greater control. In particular, it's not
possible to use the pid from a subprocess.Popen instance, since it
may already have disappeared. For instance, it makes it difficult to
use os.wait() to wait for several child processes at the same time.
The solution is simple: Add an option that disables the auto-reaper
for a Popen instance. This makes everyone happy: existing code is
unaffected, the programmer who wants to control her processes
herself is allowed to do that, and the documentation is improved to
help avoiding a nasty bug.
A patch was posted to the patch tracker as number 1187312. I
suggest it for inclusion into the next release.
|