-
-
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
Changes from all commits
cb8e422
4862fb8
83014b5
d7df812
a224c6f
7a64e68
22fb4b6
49cdc22
6db7ec3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,13 +164,15 @@ def __init__(self, registry, address, authkey, serializer): | |
| self.id_to_refcount = {} | ||
| self.id_to_local_proxy_obj = {} | ||
| self.mutex = threading.Lock() | ||
| self._handler_threads = [] | ||
|
|
||
| def serve_forever(self): | ||
| ''' | ||
| Run the server forever | ||
| ''' | ||
| self.stop_event = threading.Event() | ||
| process.current_process()._manager_server = self | ||
| accepter = None | ||
| try: | ||
| accepter = threading.Thread(target=self.accepter) | ||
| accepter.daemon = True | ||
|
|
@@ -185,15 +187,21 @@ def serve_forever(self): | |
| util.debug('resetting stdout, stderr') | ||
| sys.stdout = sys.__stdout__ | ||
| sys.stderr = sys.__stderr__ | ||
| for t in self._handler_threads: | ||
| t.join() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what prevents the handle_request threads from blocking indefinitely? |
||
| accepter.join() | ||
| self.listener.close() | ||
| sys.exit(0) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fundamentally, the accepter and handle_request threads were all being set This is likely why you see test failures for leftover env files with |
||
|
|
||
| def accepter(self): | ||
| while True: | ||
| while True and not self.stop_event.is_set(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the leftover |
||
| try: | ||
| self.listener.settimeout(0.5) | ||
| c = self.listener.accept() | ||
| except OSError: | ||
| continue | ||
| t = threading.Thread(target=self.handle_request, args=(c,)) | ||
| self._handler_threads.append(t) | ||
| t.daemon = True | ||
| t.start() | ||
|
|
||
|
|
||
| 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 |
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.
move these 2 lines outside of the try: to replace your = None initialization.