Avoid race condition with Popen.send_signal

Adam Skutt askutt at gmail.com
Tue Jan 3 08:40:05 EST 2012

On Jan 3, 7:31 am, Heiko Wundram <modeln... at modelnine.org> wrote:
> Am 03.01.2012 02:19, schrieb Adam Skutt:
> > On Jan 2, 6:09 pm, Jérôme<jer... at jolimont.fr>  wrote:
> >> What is the clean way to avoid this race condition ?
> > The fundamental race condition cannot be removed nor avoided. Ideally,
> > avoid the need to send the subprocess a signal in the first place.  If
> > it cannot be avoided, then trap the exception.
> Yes, it can be avoided, that's what the default SIGCHLD-handling
> (keeping the process as a zombie until it's explicitly collected by a
> wait*()) is for, which forces the PID not to be reused by the operating
> system until the parent has acknowledged (by actively calling wait*())
> that the child has terminated.

No, you still can see ESRCH when sending signals to a zombie process.
Code that sends signals to child processes via kill(2) must be
prepared for the call to fail at anytime since the process can die at
anytime.  It can't handle the signal, so it's treated as if it doesn't
exist by kill(2) in this case.  However, you don't have to worry about
sending the signal to the wrong process.


More information about the Python-list mailing list