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

Event loop is closed #371

Closed
omerXfaruq opened this issue Jun 20, 2022 · 6 comments
Closed

Event loop is closed #371

omerXfaruq opened this issue Jun 20, 2022 · 6 comments

Comments

@omerXfaruq
Copy link

omerXfaruq commented Jun 20, 2022

While running the tests I am receiving these warning errors, and I suspect this causes CircleCI tests to run forever and not finish.

Reproduction:
Go to the Commit and run
pytest test/test_utils.py

Related issues:
#256, #291

Not sure what causes it and how to solve it, do you have any suggestions @seifertm?

======================== 7 passed, 3 warnings in 4.21s ========================

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 746, in call_soon
    self._check_closed()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001C46AEF9D30>
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 746, in call_soon
    self._check_closed()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001C46AEF9D30>
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 746, in call_soon
    self._check_closed()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

@Puh00
Copy link

Puh00 commented Jun 21, 2022

I stumbled upon a similar issue and solved it by combining these two solutions: #30 (comment) and encode/httpx#914 (comment)

So the end result is:

# content of conftest.py
import asyncio

@pytest.yield_fixture
def event_loop():
    """Create an instance of the default event loop for each test case."""
    policy = asyncio.WindowsSelectorEventLoopPolicy()
    res = policy.new_event_loop()
    asyncio.set_event_loop(res)
    res._close = res.close
    res.close = lambda: None

    yield res

    res._close()

@omerXfaruq
Copy link
Author

Thx for the suggestion @Puh00, we've solved it with this

Btw I liked your github page a lot, it rocks 🐱

@seifertm
Copy link
Contributor

I was just looking into this issue as you posted your comment.

Glad you could solve it. I assume this can be closed.

@omerXfaruq
Copy link
Author

So to have it clear, is it a bug related to Python(there are some comments in the threads provided above), or is it related to pytest-asyncio?

@seifertm
Copy link
Contributor

@farukozderim If in doubt, it's a pytest-asyncio issue.

Honestly, I didn't manage to set up your example and reproduce the error. I checked out the repository, installed the requirements and downloaded >1GB of Python wheels. After that, the test still complained about missing dependencies, which I installed one by one. I stopped after the third and found your comment. No offense intended. I just wanted to point out that a more stripped down example would have been helpful.

I assume it's related to the use of pytest.fixture(autouse=True) you already linked (#291)

@omerXfaruq
Copy link
Author

Sorry for the inconveniences, thank you for looking into it.

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

3 participants