bpo-39995: CLN remove some locks in ProcessPoolExecutor by tomMoral · Pull Request #19788 · python/cpython

Follow-up of #19760 to try to remove some locks.

Actually, the only one that matters in term of perf is probably the one in Lib/concurrent/futures/process.py#L171 which would be concurrent with the job submission. It can be removed because this lock is here to protect against concurrent call to close which is only called in the same thread as clear so the protection is unecesary.

We can also remove the one in SafeQueue because the queue is closed (and thus the queue feeder thread join) before we call thread_wakeup.close. But this is not really changing the perf so maybe we could leave it. Let me know what you prefer.

Finally, the call to wakeup in _python_exit was indeed not protected and this could lead to the same race condition. I added a lock here to make sure we avoid this. (A bit more complicated than expected as the _python_exit was leaking in the workers).

I launched 50times the tests with @vstinner patch and did not observed the failure so I think this is working.

https://bugs.python.org/issue39995