Skip to content

Commit 339467e

Browse files
committed
gh-109593: ResourceTracker.ensure_running() calls finalizers
multiprocessing: Reduce the risk of reentrant calls to ResourceTracker.ensure_running() by running explicitly all finalizers before acquiring the ResourceTracker lock.
1 parent ced6924 commit 339467e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Lib/multiprocessing/resource_tracker.py

+7
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ def ensure_running(self):
8080
8181
This can be run from any process. Usually a child process will use
8282
the resource created by its parent.'''
83+
84+
# gh-109593: Reduce the risk of reentrant calls to ensure_running() by
85+
# running explicitly all finalizers. Otherwise, finalizers like
86+
# SemLock._cleanup() can make indirectly a reentrant call to
87+
# ensure_running().
88+
util._run_finalizers()
89+
8390
with self._lock:
8491
if self._fd is not None:
8592
# resource tracker was launched before, is it still running?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:mod:`multiprocessing`: Reduce the risk of reentrant calls to
2+
``ResourceTracker.ensure_running()`` by running explicitly all finalizers
3+
before acquiring the ``ResourceTracker`` lock. Patch by Victor Stinner.

0 commit comments

Comments
 (0)