8000 gh-88887: Cleanup `multiprocessing.resource_tracker.ResourceTracker` upon deletion by luccabb · Pull Request #130429 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-88887: Cleanup multiprocessing.resource_tracker.ResourceTracker upon deletion #130429

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

Merged
merged 21 commits into from
Mar 20, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixing _stop for None pids
  • Loading branch information
luccabb committed Mar 6, 2025
commit 8e43a8393305b49915f150f1593273fa220c6e15
20 changes: 9 additions & 11 deletions Lib/multiprocessing/resource_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,16 @@ def _reentrant_call_error(self):
raise ReentrantCallError(
"Reentrant call into the multiprocessing resource tracker")

def __del__(self):
# making sure child processess are cleaned before ResourceTracker
# gets destructed.
# see https://github.com/python/cpython/issues/88887
self._stop()

def _stop(self):
with self._lock:
if self._pid is None:
return
# This should not happen (_stop() isn't called by a finalizer)
# but we check for it anyway.
if self._lock._recursion_count() > 1:
Expand Down Expand Up @@ -191,7 +199,7 @@ def unregister(self, name, rtype):
'''Unregister name of resource with resource tracker.'''
self._send('UNREGISTER', name, rtype)

def _send(self, cmd, name, rtype):
def _send(self, cmd, name, rtype)::77
try:
self.ensure_running()
except ReentrantCallError:
Expand All @@ -212,16 +220,6 @@ def _send(self, cmd, name, rtype):
assert nbytes == len(msg), "nbytes {0:n} but len(msg) {1:n}".format(
nbytes, len(msg))

def __del__(self):
# making sure child processess are cleaned before ResourceTracker
# gets destructed.
# see https://github.com/python/cpython/issues/88887
try:
self._stop()
except (OSError, TypeError, AttributeError) as e:
pass


_resource_tracker = ResourceTracker()
ensure_running = _resource_tracker.ensure_running
register = _resource_tracker.register
Expand Down
0