-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-140267: Fixed thread leak in multiprocessing.Manager accepter thread #141734
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
prithviraj-chaudhuri
wants to merge
9
commits into
python:main
from
prithviraj-chaudhuri:fix-issue-140267
Closed
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cb8e422
Waiting for the accepter thread to finish when the serve_forever meth…
prithviraj-chaudhuri 4862fb8
Updated test_mymanager_context_prestarted to expect 0 or -signal.SIGT…
prithviraj-chaudhuri 83014b5
📜🤖 Added by blurb_it.
blurb-it[bot] d7df812
Added timeout loop
prithviraj-chaudhuri a224c6f
Added timeout and joining daemon thread
prithviraj-chaudhuri 7a64e68
Changed timeout to 0.5
prithviraj-chaudhuri 22fb4b6
Closing handler threads before accepter and after socket close
prithviraj-chaudhuri 49cdc22
Closing listener
prithviraj-chaudhuri 6db7ec3
≈≈Merge branch 'main' into fix-issue-140267
prithviraj-chaudhuri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Library/2025-11-19-05-43-58.gh-issue-140267.DTFG1E.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fixed thread leak in multiprocessing.Manager accepter thread by adding accepter.join() when before the serve_forever() method exits. | ||
| Fixed test_mymanager_context_prestarted test to expect either an exit code 0 or -signal.SIGTERM |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fundamentally, the accepter and handle_request threads were all being set
.daemon = Trueas they were never intended to be controlled and cleaned up. they'll all die as soon as the server process exits. attempting to join all of the threads is perhaps ideal but only works if they can be guaranteed not to be blocked on anything. Handler threads do blocking IO to a socket connection which is not guaranteed to have been closed because it could come from an uncooperative peer. without rewriting them to do non-blocking IO and check a stop_event themselves, joining them can't be reliable and could lead to anything making a connection to the socket being able to block cleanup.This is likely why you see test failures for leftover env files with
pymp-prefixed tmp directories or Windows \\pipe paths still laying around such asWarning -- test.test_concurrent_futures.test_process_pool leaked temporary files (1): pymp-cdk1jdmhwith this change. Those are created (by Server for its self.listener via the Listener use of default_family and call to arbitrary_address(family)) to hold the socket that the manager process uses. If the manager process is blocked instead of exiting cleanly it may still exist.