Skip to content
Merged
Changes from 1 commit
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
Next Next commit
gh-109538: Catch closed loop runtime error and issue warning
  • Loading branch information
dpr-0 committed Nov 12, 2023
commit 354780aea26261dde4141603c887f8067477f993
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