8000 bpo-35621: Support running subprocesses in asyncio when loop is executed in non-main thread by asvetlov · Pull Request #14344 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-35621: Support running subprocesses in asyncio when loop is executed in non-main thread #14344

8000
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

Merged
merged 17 commits into from
Jun 30, 2019
Merged
Changes from 2 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
0