bpo-39995: Fix race condition in ProcessPoolExecutor._ThreadWakeup#19751
bpo-39995: Fix race condition in ProcessPoolExecutor._ThreadWakeup#19751aeros wants to merge 1 commit intopython:masterfrom
Conversation
pitrou
left a comment
There was a problem hiding this comment.
I would favour a non-locking solution (hence my suggestion on the bpo issue), but this PR is faulty anyway. You could very well have the following execution sequence:
Thread A Thread B
-------- ---------
<Enters wakeup()>
if not self._closed: # Success
<Enters close()>
self._closed = True
self._not_running.wait() # Success
self._writer.close()
self._not_running.clear()
self._writer.send_bytes(b"") # Oops
|
When you're done making the requested changes, leave the comment: And if you don't make the requested changes, you will be poked with soft cushions! |
|
@pitrou Ah, I had somehow not considered that scenario and got a bit carried away with the surface-level success of it appearing to resolve |
I wrote PR #19758 which is similar to this one, but doesn't have this race condition. |
Addresses a race condition in
ProcessPoolExecutor._ThreadWakeupby using athreading.Eventto ensure either end of its pipe is not closed while it is actively sending or receiving bytes.Fixes an intermittent failure in
test_concurrent_futures.ProcessPoolSpawnProcessPoolExecutorTest.test_killed_child, and aims to fix some of the others reported in the bpo issue.https://bugs.python.org/issue39995