[issue25960] Popen.wait() hangs when called from a signal handler when os.waitpid() does not

Mike Frysinger report at bugs.python.org
Tue Feb 25 01:06:45 EST 2020


Mike Frysinger <vapier at users.sourceforge.net> added the comment:

if threading.active_count() returns 1, then you know there's one thread, and you're it, so it's not racey, and a lock ins't needed.

thinking a bit more, what if the code just use a recursive lock ?  that would restore the single threaded status quo without overly complicating the code.

thinking a bit more, i think you're right that this is inherently racy, but not because using the APIs in async context isn't permissible.  if a signal is delivered after Popen.wait() finishes the OS waitpid call, but before it releases the lock, then the child state is not recoverable from the signal handler.

in our case, we're using the signal handler to kill the process, and we want to make sure it's exited, so being able to get the exact exit status is not important to us, just making sure we can detect when the process is gone.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue25960>
_______________________________________


More information about the Python-bugs-list mailing list