Skip to content

asyncio internals throw RuntimeError: Event loop is closed on script exit #92841

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

Closed
arhadthedev opened this issue May 16, 2022 · 3 comments
Closed
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@arhadthedev
Copy link
Member

Actual behavior

>>> import asyncio
>>> import aiohttp
>>>
>>> async def main():
...     async with aiohttp.ClientSession() as session:
...         async with session.get('https://example.com/'):
...             pass
...
>>> asyncio.run(main())
>>> exit()
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000017BF133F760>
Traceback (most recent call last):
  File "C:\Program Files\Python310\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Program Files\Python310\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Program Files\Python310\lib\asyncio\base_events.py", line 750, in call_soon
    self._check_closed()
  File "C:\Program Files\Python310\lib\asyncio\base_events.py", line 515, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

This issue was reported in aio-libs/aiohttp#4324 so the reproducer is copied from there.

Expected behavior

Normal exit without termination. There is no user-created loop to be closed manually.

Your environment

  • CPython versions tested on: 3.10.4
  • Operating system and architecture: Windows 10
@arhadthedev arhadthedev added the type-bug An unexpected behavior, bug, or error label May 16, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 17, 2022
…honGH-92842)

(cherry picked from commit 33880b4)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 17, 2022
…honGH-92842)

(cherry picked from commit 33880b4)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
miss-islington added a commit that referenced this issue May 17, 2022
(cherry picked from commit 33880b4)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
@hauntsaninja
Copy link
Contributor

Thanks, seems like we can close this one out

@hauntsaninja
Copy link
Contributor

Oh never mind, the 3.10 backport hasn't been merged

@hauntsaninja hauntsaninja reopened this May 22, 2022
ambv pushed a commit that referenced this issue Jun 28, 2022
…GH-92904)

(cherry picked from commit 33880b4)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
@arhadthedev arhadthedev moved this to Done in asyncio Jun 30, 2022
wookayin added a commit to wookayin/pynvim that referenced this issue Oct 15, 2023
python < 3.10.6 has a bug on proactor-based pipe transport: when a
`_ProactorBasePipeTransport` instance is garbage-collected (usually
after the associated event loop is closed), it will raise an error.

For older versions of python, we apply the same monkey-patchin to
suppress warnings (actually these are errors).

Ref: python/cpython#83413 and python/cpython#92841

CI output (pytest warnings):

```
======================= 71 passed, 66 warnings in 6.55s =======================
 Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000021A9534F700>
  Traceback (most recent call last):
    File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\asyncio\proactor_events.py", line 115, in __del__
      _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
    File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\asyncio\proactor_events.py", line 79, in __repr__
      info.append(f'fd={self._sock.fileno()}')
    File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\asyncio\windows_utils.py", line 102, in fileno
      raise ValueError("I/O operation on closed pipe")
  ValueError: I/O operation on closed pipe
  Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000021A9534F700>
  Traceback (most recent call last):
    File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\asyncio\proactor_events.py", line 115, in __del__
    File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\asyncio\proactor_events.py", line 79, in __repr__
    File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\asyncio\windows_utils.py", line 102, in fileno
  ValueError: I/O operation on closed pipe
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

3 participants