diff options
author | DPR <dpr-0xff@pm.me> | 2023-11-15 01:17:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-15 01:17:51 (GMT) |
commit | e0f512797596282bff63260f8102592aad37cdf1 (patch) | |
tree | b0d0065f668f65b07e03d63eb0a3b6065e5c6646 /Lib/asyncio | |
parent | fe9db901b2446b047e537447ea5bad3d470b0f78 (diff) | |
download | cpython-e0f512797596282bff63260f8102592aad37cdf1.zip cpython-e0f512797596282bff63260f8102592aad37cdf1.tar.gz cpython-e0f512797596282bff63260f8102592aad37cdf1.tar.bz2 |
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>
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/streams.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py index f82b10c..ffb48b9 100644 --- a/Lib/asyncio/streams.py +++ b/Lib/asyncio/streams.py @@ -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: |