[issue42110] race condition in ThreadChildWatcher (default) and MultiLoopChildWatcher

Alan Jenkins report at bugs.python.org
Thu Oct 22 11:09:14 EDT 2020


Alan Jenkins <alan.christopher.jenkins at gmail.com> added the comment:

Put the other way, if you wanted to fix this bug in ThreadedChildWatcher, and go as far as allowing cancelling Process.wait(), followed by kill() / send_signal(), then I think you need -

* siginterrupt(SIGCHLD, 1)
* not to mind about any random C code that doesn't really handle being interrupted.  Like printf(), ho hum.  https://groups.google.com/g/comp.unix.programmer/c/QZmFw1VytYs/m/BSBXBHTI1REJ
* add & use a new call like os.waitpid_interruptible(), which doesn't restart on EINTR, as a workaround for PEP-475.
* set a "stop" flag for the watcher thread
* use threading.pthread_kill() (available on *most* python platforms) to interrupt the watcher thread.  Spoof SIGCHLD, this will avoid conflicts with a python handler for any other signal.
* wait for the watcher thread to finish using Thread.join()
* now you can safely find out whether the child process has been reaped, or whether it's safe to kill it.

----------

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


More information about the Python-bugs-list mailing list