Skip to content

Commit

Permalink
pythongh-109593: ResourceTracker.ensure_running() calls finalizers
Browse files Browse the repository at this point in the history
multiprocessing: Reduce the risk of reentrant calls to
ResourceTracker.ensure_running() by running explicitly all finalizers
before acquiring the ResourceTracker lock.
  • Loading branch information
vstinner committed Sep 20, 2023
1 parent ced6924 commit 339467e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Lib/multiprocessing/resource_tracker.py
Expand Up @@ -80,6 +80,13 @@ def ensure_running(self):
This can be run from any process. Usually a child process will use
the resource created by its parent.'''

# gh-109593: Reduce the risk of reentrant calls to ensure_running() by
# running explicitly all finalizers. Otherwise, finalizers like
# SemLock._cleanup() can make indirectly a reentrant call to
# ensure_running().
util._run_finalizers()

with self._lock:
if self._fd is not None:
# resource tracker was launched before, is it still running?
Expand Down
@@ -0,0 +1,3 @@
:mod:`multiprocessing`: Reduce the risk of reentrant calls to
``ResourceTracker.ensure_running()`` by running explicitly all finalizers
before acquiring the ``ResourceTracker`` lock. Patch by Victor Stinner.

0 comments on commit 339467e

Please sign in to comment.