From 7080a8bba86db1ea38372183a90d82bfa7d6d8b1 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Wed, 7 Jul 2021 20:42:32 +0800 Subject: [PATCH] Use `MultiLoopChildWatcher` in tests where available PR #5862 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 * https://docs.python.org/3/library/asyncio-policy.html#asyncio.MultiLoopChildWatcher Co-authored-by: Sviatoslav Sydorenko --- CHANGES/3450.bugfix | 1 + CONTRIBUTORS.txt | 1 + aiohttp/test_utils.py | 11 ++++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 CHANGES/3450.bugfix diff --git a/CHANGES/3450.bugfix b/CHANGES/3450.bugfix new file mode 100644 index 00000000000..6b82b4c0481 --- /dev/null +++ b/CHANGES/3450.bugfix @@ -0,0 +1 @@ +Started using `MultiLoopChildWatcher` when it's available under POSIX while setting up the test I/O loop. diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 502efb67a20..b9361827b66 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -241,6 +241,7 @@ Pawel Miech Pepe Osca Philipp A. Pieter van Beek +Qiao Han Rafael Viotti Raphael Bialon Raúl Cumplido diff --git a/aiohttp/test_utils.py b/aiohttp/test_utils.py index e8ebb6d4ed0..06155bae19f 100644 --- a/aiohttp/test_utils.py +++ b/aiohttp/test_utils.py @@ -490,7 +490,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.MultiLoopChildWatcher() + except AttributeError: # Python < 3.8 + watcher = asyncio.SafeChildWatcher() watcher.attach_loop(loop) with contextlib.suppress(NotImplementedError): policy.set_child_watcher(watcher)