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

This commit is contained in:
Andrew Svetlov 2019-06-30 12:54:59 +03:00 committed by GitHub
parent 5cbbbd73a6
commit 0d671c04c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 378 additions and 72 deletions

View file

@ -1,5 +1,6 @@
"""Utilities shared by tests."""
import asyncio
import collections
import contextlib
import io
@ -512,6 +513,18 @@ class TestCase(unittest.TestCase):
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