mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.11] gh-110205: Fix asyncio ThreadedChildWatcher._join_threads() (GH-110884) (#111413)
- `ThreadedChildWatcher.close()` is now *officially* a no-op; `_join_threads()` never did anything.
- Threads created by that class are now named `asyncio-waitpid-NNN`.
- `test.test_asyncio.utils.TestCase.close_loop()` now waits for the child watcher's threads, but not forever; if a thread hangs, it raises `RuntimeError`.
(cherry picked from commit c3bb10c930
)
Co-authored-by: Guido van Rossum <guido@python.org>
This commit is contained in:
parent
e84b06c05a
commit
1a01ca44d6
2 changed files with 10 additions and 12 deletions
|
@ -1363,14 +1363,7 @@ class ThreadedChildWatcher(AbstractChildWatcher):
|
|||
return True
|
||||
|
||||
def close(self):
|
||||
self._join_threads()
|
||||
|
||||
def _join_threads(self):
|
||||
"""Internal: Join all non-daemon threads"""
|
||||
threads = [thread for thread in list(self._threads.values())
|
||||
if thread.is_alive() and not thread.daemon]
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
@ -1389,7 +1382,7 @@ class ThreadedChildWatcher(AbstractChildWatcher):
|
|||
def add_child_handler(self, pid, callback, *args):
|
||||
loop = events.get_running_loop()
|
||||
thread = threading.Thread(target=self._do_waitpid,
|
||||
name=f"waitpid-{next(self._pid_counter)}",
|
||||
name=f"asyncio-waitpid-{next(self._pid_counter)}",
|
||||
args=(loop, pid, callback, args),
|
||||
daemon=True)
|
||||
self._threads[pid] = thread
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue