Skip to content

gh-109593: ResourceTracker.ensure_running() calls finalizers #109620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/multiprocessing/resource_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# this resource tracker process, "killall python" would probably leave unlinked
# resources.

import gc
import os
import signal
import sys
Expand Down Expand Up @@ -80,6 +81,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 a garbage collection. Otherwise, finalizers like
# SemLock._cleanup() can make indirectly a reentrant call to
# ensure_running().
gc.collect()

with self._lock:
if self._fd is not None:
# resource tracker was launched before, is it still running?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:mod:`multiprocessing`: Reduce the risk of reentrant calls to
``ResourceTracker.ensure_running()`` by running explicitly a garbage
collection, to call pending finalizers, before acquiring the
``ResourceTracker`` lock. Patch by Victor Stinner.