FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-35621: Support running subprocesses in asyncio when loop is executed in non-main thread by asvetlov · Pull Request #14344 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
Work on
  • Loading branch information
asvetlov committed Jun 4, 2019
commit ef1e21cfb1e7b737abf9be61b51d9dd2eaee560a
14 changes: 11 additions & 3 deletions Lib/asyncio/unix_events.py
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
Expand Up @@ -1236,16 +1236,22 @@ def is_active(self):
return True

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

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
pass

def __del__(self, _warn=warnings.warn):
threads = [thread for thread in list(self._threads.values())
if thread.is_alive()]
if threads:
_warn(f"{self.__class__} has registered but not finished child processes",
ResourceWarning,
source=self)

def add_child_handler(self, pid, callback, *args):
loop = events.get_running_loop()
thread = threading.Thread(target=self._do_waitpid,
Expand Down Expand Up @@ -1289,6 +1295,8 @@ def _do_waitpid(self, loop, expected_pid, callback, args):
loop.call_soon_threadsafe(callback, pid, returncode, *args)

self._threads.pop(expected_pid)
import time
time.sleep(0.5)


class _UnixDefaultEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_asyncio/utils.py
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
@@ -1,5 +1,6 @@
"""Utilities shared by tests."""

import asyncio
import collections
import contextlib
import io
Expand Down Expand Up @@ -512,6 +513,18 @@ def close_loop(loop):
if executor is not None:
executor.shutdown(wait=True)
loop.close()
policy = support.maybe_get_event_loop_policy()
if policy is not None:
try:
watcher = policy.get_child_watcher()
except NotImplementedError:
# watcher is not implemented by EventLoopPolicy, e.g. Windows
pass
else:
if isinstance(watcher, asyncio.ThreadedChildWatcher):
threads = list(watcher._threads.values())
for thread in threads:
thread.join()

def set_event_loop(self, loop, *, cleanup=True):
assert loop is not None
Expand Down

Back | FazBrowse Home | New Git URL