Skip to content

Commit

Permalink
Uvloop 0.10 workaround (aio-libs#3046)
Browse files Browse the repository at this point in the history
* Dont install child watcher explicitly

* Setup a policy before creating a loop
  • Loading branch information
asvetlov authored Jun 1, 2018
1 parent 0933b6c commit f426da7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 6 additions & 4 deletions aiohttp/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ def pytest_generate_tests(metafunc):
return

loops = metafunc.config.option.aiohttp_loop
avail_factories = {'pyloop': asyncio.new_event_loop}
avail_factories = {'pyloop': asyncio.DefaultEventLoopPolicy}

if uvloop is not None: # pragma: no cover
avail_factories['uvloop'] = uvloop.new_event_loop
avail_factories['uvloop'] = uvloop.EventLoopPolicy

if tokio is not None: # pragma: no cover
avail_factories['tokio'] = tokio.new_event_loop
avail_factories['tokio'] = tokio.EventLoopPolicy

if loops == 'all':
loops = 'pyloop,uvloop?,tokio?'
Expand All @@ -200,7 +200,9 @@ def pytest_generate_tests(metafunc):
@pytest.fixture
def loop(loop_factory, fast, loop_debug):
"""Return an instance of the event loop."""
with loop_context(loop_factory, fast=fast) as _loop:
policy = loop_factory()
asyncio.set_event_loop_policy(policy)
with loop_context(fast=fast) as _loop:
if loop_debug:
_loop.set_debug(True) # pragma: no cover
asyncio.set_event_loop(_loop)
Expand Down
8 changes: 7 additions & 1 deletion aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,14 @@ def setup_test_loop(loop_factory=asyncio.new_event_loop):
once they are done with the loop.
"""
loop = loop_factory()
try:
module = loop.__class__.__module__
skip_watcher = 'uvloop' in module
except AttributeError: # pragma: no cover
# Just in case
skip_watcher = True
asyncio.set_event_loop(loop)
if sys.platform != "win32":
if sys.platform != "win32" and not skip_watcher:
policy = asyncio.get_event_loop_policy()
watcher = asyncio.SafeChildWatcher()
watcher.attach_loop(loop)
Expand Down

0 comments on commit f426da7

Please sign in to comment.