Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 9 additions & 0 deletions Lib/multiprocessing/resource_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ 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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching some exceptions is fine. But catching any exception is not ok. You should not ignore KeyboardInterrupt for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to catch OSError, TypeError, AttributeError only

pass


_resource_tracker = ResourceTracker()
ensure_running = _resource_tracker.ensure_running
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixing multiprocessing Resource Tracker process leaking
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fixing multiprocessing Resource Tracker process leaking
Fixing multiprocessing Resource Tracker process leaking.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the issue specific to Python running as the pid 1? If yes, it might be useful to mention it in the Changelog entry.

Copy link
Contributor Author

@luccabb luccabb Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the leaking happens regardless of PID 1. Python relies on kernel's process handling code to clean up the process, which works fine for most cases.

A case where it won't work is when running Python as PID 1 and there's no signal processing handler to reap zombies on client code

Loading