Open
Description
Bug report
in a number of places a ResourceWarning is issued before cleaning up a resource eg
cpython/Lib/asyncio/unix_events.py
Lines 559 to 562 in 944ff8c
normally this is fine - however if you're running with
-Werror
these warnings are raised as exceptions and so prevent the underlying resource from being cleaned up. This is in particular a problem when running a test suite with filterwarnings=['error', ...
where resource cleanup can be delayed for many tests.
I think these should instead be restructured as:
def __del__(self, _warn=warnings.warn):
if self._pipe is not None:
msg = f"unclosed transport {self!r}" # grab the repr before closing the pipe so it displays as "open" still
self._pipe.close()
_warn(msg, ResourceWarning, source=self) # issue the warning after closing the resource
Your environment
- CPython versions tested on:
- Operating system and architecture: