Skip to content
Closed
Changes from all 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
8 changes: 7 additions & 1 deletion Lib/asyncio/unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,12 +1230,15 @@ class ThreadedChildWatcher(AbstractChildWatcher):

def __init__(self):
self._pid_counter = itertools.count(0)
self._threads = {}

def is_active(self):
return True

def close(self):
pass
threads = list(self._threads.values())
for thread in threads:
thread.join()

def __enter__(self):
return self
Expand All @@ -1249,6 +1252,7 @@ def add_child_handler(self, pid, callback, *args):
name=f"waitpid-{next(self._pid_counter)}",
args=(loop, pid, callback, args),
daemon=True)
self._threads[pid] = thread
thread.start()

def remove_child_handler(self, pid):
Expand Down Expand Up @@ -1284,6 +1288,8 @@ def _do_waitpid(self, loop, expected_pid, callback, args):
else:
loop.call_soon_threadsafe(callback, pid, returncode, *args)

self._threads.pop(expected_pid)


class _UnixDefaultEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
"""UNIX event loop policy with a watcher for child processes."""
Expand Down