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

Alan Jenkins report at bugs.python.org
Thu Oct 22 10:29:06 EDT 2020


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

There's one way to fix this in MultiLoopChildWatcher (but not ThreadedChildWatcher).  Make sure the waitpid() runs on the same thread that created the subprocess.  Prototype: https://github.com/sourcejedi/cpython/commit/92f979bce4582e807facb1c274a962b3caf0d2eb

The other approach would be to copy subprocess.wait(timeout) - keep waking up regularly and polling to see if the process has exited yet.

I'm not convinced ThreadedChildWatcher is fixable.  You can't call waitpid() in one thread, and let someone call kill() in a different thread.

You could try avoiding calling waitpid() until someone does `await asyncio.subprocess.Process.wait()`.  I think I didn't like it because - what happens if you cancel a wait() task?  I think you want to cancel the waitpid() so you could safely kill() again... And we don't have any way to cancel the blocking waitpid() call, at least not from python, definitely not since PEP-475.

----------

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


More information about the Python-bugs-list mailing list