[3.11] gh-109538: Catch closed loop runtime error and issue warning (GH-111983) (#112141)

Issue a ResourceWarning instead.

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
(cherry picked from commit e0f5127975)
This commit is contained in:
DPR 2023-11-21 07:12:17 +08:00 committed by GitHub
parent 6c51c84b39
commit 13975051b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 2 deletions

View file

@ -404,8 +404,11 @@ class StreamWriter:
def __del__(self):
if not self._transport.is_closing():
self.close()
if self._loop.is_closed():
warnings.warn("loop is closed", ResourceWarning)
else:
self.close()
warnings.warn(f"unclosed {self!r}", ResourceWarning)
class StreamReader: