Closed
Description
Bug report
Bug description:
PR #107650 added a StreamWriter.__del__
that emits a ResourceWarning if a StreamWriter is not closed by the time it is garbage collected, and it has been backported as 3.11.5. However, if the event loop has already been closed by the time this happens, it causes a RuntimeError message to be displayed. It's non-fatal because exceptions raised by __del__
are ignored, but it causes an error message to be displayed to the user (as opposed to ResourceWarning, which is only shown when one opts in).
Code like the following used to run without any visible error, but now prints a traceback (and does not report the ResourceWarning for the unclosed StreamWriter when run with -X dev
):
#!/usr/bin/env python3
import asyncio
async def main():
global writer
reader, writer = await asyncio.open_connection("127.0.0.1", 22)
asyncio.run(main())
Output in 3.11.5:
Exception ignored in: <function StreamWriter.__del__ at 0x7fd54ee11080>
Traceback (most recent call last):
File "/usr/lib/python3.11/asyncio/streams.py", line 396, in __del__
File "/usr/lib/python3.11/asyncio/streams.py", line 344, in close
File "/usr/lib/python3.11/asyncio/selector_events.py", line 860, in close
File "/usr/lib/python3.11/asyncio/base_events.py", line 761, in call_soon
File "/usr/lib/python3.11/asyncio/base_events.py", line 519, in _check_closed
RuntimeError: Event loop is closed
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
only security fixesonly security fixesAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
Done