summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorDPR <dpr-0xff@pm.me>2023-11-15 01:17:51 (GMT)
committerGitHub <noreply@github.com>2023-11-15 01:17:51 (GMT)
commite0f512797596282bff63260f8102592aad37cdf1 (patch)
treeb0d0065f668f65b07e03d63eb0a3b6065e5c6646 /Lib/asyncio
parentfe9db901b2446b047e537447ea5bad3d470b0f78 (diff)
downloadcpython-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.py8
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: