gh-109538: Avoid RuntimeError when StreamWriter is deleted with closed loop (#111983)

Issue a ResourceWarning instead.

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
This commit is contained in:
DPR 2023-11-15 09:17:51 +08:00 committed by GitHub
parent fe9db901b2
commit e0f5127975
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 5 deletions

View file

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