[issue38744] python 3.8 hang in multiprocessing.Pool() locking on FreeBSD / Linux

Pablo Galindo Salgado report at bugs.python.org
Sat Mar 14 22:15:13 EDT 2020


Pablo Galindo Salgado <pablogsal at gmail.com> added the comment:

I am mentoring @BTaskaya and I asked to take a look a this. After some debugging, we found that the problem is the following:

When the pull is not used via the context manager or terminate() is called, there is a system in multiprocessing.util that handles finalization of all pools via an atexit handler (the Finalize) class. This class registers the _terminate_pool handler in the registry of finalizers of the module, and that registry is called on interpreter exit via _exit_function. 

The problem is that the "happy" path with the context manager or manual call to finalize() does some extra steps that _terminate_pool does not:

        def terminate(self):
            util.debug('terminating pool')
            self._state = TERMINATE
            self._worker_handler._state = TERMINATE
            self._change_notifier.put(None)
            self._terminate()

In this code self._terminate() calls _terminate_pool. The step that is not executed when the atexit() handler calls _terminate_pool is pinging the _change_notifier queue to unblock the maintenance threads.

The fix is moving the "self._change_notifier.put(None)" to the _terminate_pool function.

----------

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


More information about the Python-bugs-list mailing list