Skip to content

Commit

Permalink
Use MultiLoopChildWatcher in tests where available
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge and webknjaz authored Jul 7, 2021
1 parent 5b23426 commit 7080a8b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/3450.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Started using `MultiLoopChildWatcher` when it's available under POSIX while setting up the test I/O loop.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ Pawel Miech
Pepe Osca
Philipp A.
Pieter van Beek
Qiao Han
Rafael Viotti
Raphael Bialon
Raúl Cumplido
Expand Down
11 changes: 10 additions & 1 deletion aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7080a8b

Please sign in to comment.