Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Lib/asyncio/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,12 @@ async def start_tls(self, sslcontext, *,

def __del__(self, warnings=warnings):
if not self._transport.is_closing():
self.close()
warnings.warn(f"unclosed {self!r}", ResourceWarning)

try:
self.close()
except RuntimeError:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching all RuntimeErrors always feels scary -- it could mark other, more serious bugs. How about only issuing the new warning if self._loop.is_closed()?

warnings.warn("loop is closed", ResourceWarning)
else:
warnings.warn(f"unclosed {self!r}", ResourceWarning)

class StreamReader:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Issue warning message instead of having :class:`RuntimeError` be displayed when event loop has already been closed at :meth:`StreamWriter.__del__`.