Skip to content

Commit 68f0262

Browse files
patchback[bot]webknjazsweatybridge
authored
[PR #5862/7080a8bb backport][3.8] Use MultiLoopChildWatcher in tests where available (#5863)
Co-authored-by: Sviatoslav Sydorenko <[email protected]> Co-authored-by: Han Qiao <[email protected]>
1 parent 420cc71 commit 68f0262

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

CHANGES/3450.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Started using `MultiLoopChildWatcher` when it's available under POSIX while setting up the test I/O loop.

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ Pawel Miech
230230
Pepe Osca
231231
Philipp A.
232232
Pieter van Beek
233+
Qiao Han
233234
Rafael Viotti
234235
Raphael Bialon
235236
Raúl Cumplido

aiohttp/test_utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,16 @@ def setup_test_loop(
519519
asyncio.set_event_loop(loop)
520520
if sys.platform != "win32" and not skip_watcher:
521521
policy = asyncio.get_event_loop_policy()
522-
watcher = asyncio.SafeChildWatcher()
522+
watcher: asyncio.AbstractChildWatcher
523+
try: # Python >= 3.8
524+
# Refs:
525+
# * https://github.com/pytest-dev/pytest-xdist/issues/620
526+
# * https://stackoverflow.com/a/58614689/595220
527+
# * https://bugs.python.org/issue35621
528+
# * https://github.com/python/cpython/pull/14344
529+
watcher = asyncio.MultiLoopChildWatcher()
530+
except AttributeError: # Python < 3.8
531+
watcher = asyncio.SafeChildWatcher()
523532
watcher.attach_loop(loop)
524533
with contextlib.suppress(NotImplementedError):
525534
policy.set_child_watcher(watcher)

0 commit comments

Comments
 (0)