summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/utils.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2019-06-30 09:54:59 (GMT)
committerGitHub <noreply@github.com>2019-06-30 09:54:59 (GMT)
commit0d671c04c39b52e44597491b893eb0b6c86b3d45 (patch)
treeb48295515be5ed2aed7babe62a924266edfdde6a /Lib/test/test_asyncio/utils.py
parent5cbbbd73a6acb6f96f5d6646aa7498d3dfb1706d (diff)
downloadcpython-0d671c04c39b52e44597491b893eb0b6c86b3d45.zip
cpython-0d671c04c39b52e44597491b893eb0b6c86b3d45.tar.gz
cpython-0d671c04c39b52e44597491b893eb0b6c86b3d45.tar.bz2
bpo-35621: Support running subprocesses in asyncio when loop is executed in non-main thread (GH-14344)
Diffstat (limited to 'Lib/test/test_asyncio/utils.py')
-rw-r--r--Lib/test/test_asyncio/utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/utils.py b/Lib/test/test_asyncio/utils.py
index cb373d5..5b4bb12 100644
--- a/Lib/test/test_asyncio/utils.py
+++ b/Lib/test/test_asyncio/utils.py
@@ -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