Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SafeChildWatcher is not reinstalled properly after the second test is loop fixture is not used #3199

Open
tardyp opened this issue Aug 17, 2018 · 3 comments

Comments

@tardyp
Copy link

tardyp commented Aug 17, 2018

Long story short

When moving to aiohttp 3.3+, my tests suddently hang at await process.wait()
but only after one test has run previously

Expected behaviour

process.wait() returns when the process finishes

Actual behaviour

process.wait() never returns

Steps to reproduce

pip install aiohttp pytest pytest-aiohttp pytest-asyncio

run the following test suite:

import asyncio


async def test_basic():
    sleep_proc = await asyncio.create_subprocess_exec("sleep", '0.1',)
    await sleep_proc.wait()


async def test_basic2():
    sleep_proc = await asyncio.create_subprocess_exec("sleep", '0.1',)
    await sleep_proc.wait()

The second test will fail.

Your environment

macos python3.7 from brew.

Rootcause start

if I change SafeChildWatcher installer in test_utils.py:setup_test_loop to following code, the test will work

    if sys.platform != "win32" and not skip_watcher:
        policy = asyncio.get_event_loop_policy()
        if not policy.get_child_watcher():
            watcher = asyncio.SafeChildWatcher()
            watcher.attach_loop(loop)
            with contextlib.suppress(NotImplementedError):
                policy.set_child_watcher(watcher)
    return loop
@tardyp
Copy link
Author

tardyp commented Aug 17, 2018

looks like this comes from this commit:
8e76a4a

if I look at the code, I don't see why it is needed.

asyncio.get_child_watcher() will always automatically create the default safe childwatcher

https://github.com/python/cpython/blame/master/Lib/asyncio/unix_events.py#L1097

@tardyp
Copy link
Author

tardyp commented Aug 17, 2018

Another fix is to use loop in my test fixtures

@tardyp tardyp changed the title SafeChildWatcher is not reinstalled properly after the second test SafeChildWatcher is not reinstalled properly after the second test is loop fixture is not used Aug 17, 2018
@tardyp
Copy link
Author

tardyp commented Sep 27, 2018

Forgot to update on this.
This issue is fixed by adding loop in the fixture list for each test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant