[issue39360] python3.8 regression - ThreadPool join via __del__ hangs forever

Arkadiusz Miśkiewicz report at bugs.python.org
Sun Mar 15 05:40:36 EDT 2020


Arkadiusz Miśkiewicz <arekm at maven.pl> added the comment:

I've applied pull request patch (which looks a bit weird to me, removes something then adds the same thing back etc https://patch-diff.githubusercontent.com/raw/python/cpython/pull/19009.patch). Essentially the change is:

diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py
index b223d6aa72..8bd9608b0e 100644
--- a/Lib/multiprocessing/pool.py
+++ b/Lib/multiprocessing/pool.py
@@ -682,7 +682,15 @@ class Pool(object):
         # this is guaranteed to only be called once
         util.debug('finalizing pool')

-        worker_handler._state = TERMINATE
+        # Explicitly do the cleanup here if it didn't come from terminate()
+        # (required for if the queue will block, if it is already closed)
+        if worker_handler._state != TERMINATE:
+            # Notify that the worker_handler state has been changed so the
+            # _handle_workers loop can be unblocked (and exited) in order to
+            # send the finalization sentinel all the workers.
+            worker_handler._state = TERMINATE
+            change_notifier.put(None)
+
         task_handler._state = TERMINATE

         util.debug('helping task handler/workers to finish')


Unfortunately test case from first message in this bug report still hangs for me with this applied.

----------

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


More information about the Python-bugs-list mailing list