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

RuntimeError: Event loop is closed #178

Closed
dimaqq opened this issue Jul 10, 2020 · 2 comments · Fixed by #220
Closed

RuntimeError: Event loop is closed #178

dimaqq opened this issue Jul 10, 2020 · 2 comments · Fixed by #220

Comments

@dimaqq
Copy link

dimaqq commented Jul 10, 2020

After upgrading to pytest==5.4.3 pytest-asyncio==0.14.0 I'm getting transient(?) test failures and all I see in the log is this:

=================================== FAILURES ===================================
___________________________ test_xx ___________________________

kwargs = {'xx': XxFixture(, ...}
 
    @functools.wraps(func)
    def inner(**kwargs):
>       coro = func(**kwargs)
 
/root/.cache/pypoetry/virtualenvs/xx-py3.8/lib/python3.8/site-packages/pytest_asyncio/plugin.py:175: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/root/.cache/pypoetry/virtualenvs/xx-py3.8/lib/python3.8/site-packages/pytest_asyncio/plugin.py:175: in inner
    coro = func(**kwargs)
/root/.cache/pypoetry/virtualenvs/xx-py3.8/lib/python3.8/site-packages/pytest_asyncio/plugin.py:177: in inner
    task = asyncio.ensure_future(coro, loop=_loop)
/usr/local/lib/python3.8/asyncio/tasks.py:661: in ensure_future
    task = loop.create_task(coro_or_future)
/usr/local/lib/python3.8/asyncio/base_events.py:429: in create_task
    self._check_closed()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <_UnixSelectorEventLoop running=False closed=True debug=False>

    def _check_closed(self):
        if self._closed:
>           raise RuntimeError('Event loop is closed')
E           RuntimeError: Event loop is closed

/usr/local/lib/python3.8/asyncio/base_events.py:508: RuntimeError
---------------------------- Captured stdout setup -----------------------------

There are some fragile tests in the project and we use flaky to manage those, so I see this error only when some test fails thrice.
Weirdly I don't get to see the actual test failure/cause in this case.

At the moment I'm at a loss as to how to debug it 🤔

@dimaqq dimaqq changed the title Event loop is closed RuntimeError: Event loop is closed Jul 29, 2020
@dimaqq
Copy link
Author

dimaqq commented Jul 29, 2020

MRE: https://github.com/dimaqq/mre-loop-closed

Key circumstances: pytest, pytest-asyncio, flaky and failing test.
Instead of a failure, an error is reported.
In fact, first test failure breaks the harness and "flaky" test is not retried.

@dimaqq
Copy link
Author

dimaqq commented Jul 29, 2020

A curious observation, when the test is annotated @flaky(max_runs=10), the error backtrace has 10 (or possibly 10 - 1) levels of pytest-asyncio coro wrap:

site-packages/pytest_asyncio/plugin.py:175:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
site-packages/pytest_asyncio/plugin.py:175: in inner
    coro = func(**kwargs)
site-packages/pytest_asyncio/plugin.py:175: in inner
    coro = func(**kwargs)
site-packages/pytest_asyncio/plugin.py:175: in inner
    coro = func(**kwargs)
site-packages/pytest_asyncio/plugin.py:175: in inner
    coro = func(**kwargs)
site-packages/pytest_asyncio/plugin.py:175: in inner
    coro = func(**kwargs)
site-packages/pytest_asyncio/plugin.py:175: in inner
    coro = func(**kwargs)
site-packages/pytest_asyncio/plugin.py:175: in inner
    coro = func(**kwargs)
site-packages/pytest_asyncio/plugin.py:175: in inner
    coro = func(**kwargs)
site-packages/pytest_asyncio/plugin.py:177: in inner
    task = asyncio.ensure_future(coro, loop=_loop)
asyncio/tasks.py:661: in ensure_future
    task = loop.create_task(coro_or_future)
asyncio/base_events.py:429: in create_task
    self._check_closed()

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

Successfully merging a pull request may close this issue.

1 participant