Avoid race condition with Popen.send_signal

Adam Skutt askutt at gmail.com
Mon Jan 2 22:16:50 EST 2012


On Jan 2, 8:44 pm, Cameron Simpson <c... at zip.com.au> wrote:
> On 02Jan2012 20:31, Devin Jeanpierre <jeanpierr... at gmail.com> wrote:
> | > I think that catching the exception is probably the most Pythonic way.
> |
> | It's the only correct way.
>
> Indeed, but be precise - chek that it _is_ error 3, or more portably,
> errno.ESRCH. POSIX probably mandates that that is a 3, but the symbol
> should track the local system if it differs. Example:
>

No. It is possible (however unlikely) for EPERM to be legitimately
returned in this case.  Anything other than EINVAL should be
interpreted as "The child process is dead".  Hence why you should
avoid sending the signal in the first place: the situations where you
don't run the risk of possibly killing an innocent bystander are
pretty narrow.  While unlikely on modern UNiX and Linux, IMO it's best
to avoid the issue altogether whenever possible.

Adam



More information about the Python-list mailing list