From bea959a4ce195405939c40f184c5189206064447 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Mon, 25 Jan 2021 13:06:07 +0100 Subject: [PATCH] Use ThreadedChildWatcher in tests where available Refs: * https://github.com/pytest-dev/pytest-xdist/issues/620 * https://stackoverflow.com/a/58614689/595220 * https://bugs.python.org/issue35621 * https://github.com/python/cpython/pull/14344 --- aiohttp/test_utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/aiohttp/test_utils.py b/aiohttp/test_utils.py index dd6c91c368e..0786a751d19 100644 --- a/aiohttp/test_utils.py +++ b/aiohttp/test_utils.py @@ -506,7 +506,16 @@ def setup_test_loop( asyncio.set_event_loop(loop) if sys.platform != "win32" and not skip_watcher: policy = asyncio.get_event_loop_policy() - watcher = asyncio.SafeChildWatcher() + watcher: asyncio.AbstractChildWatcher + try: # Python >= 3.8 + # Refs: + # * https://github.com/pytest-dev/pytest-xdist/issues/620 + # * https://stackoverflow.com/a/58614689/595220 + # * https://bugs.python.org/issue35621 + # * https://github.com/python/cpython/pull/14344 + watcher = asyncio.ThreadedChildWatcher() + except AttributeError: # Python < 3.8 + watcher = asyncio.SafeChildWatcher() watcher.attach_loop(loop) with contextlib.suppress(NotImplementedError): policy.set_child_watcher(watcher)