diff options
author | Kumar Aditya <kumaraditya@python.org> | 2023-08-05 12:18:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-05 12:18:15 (GMT) |
commit | 41178e41995992bbe417f94bce158de93f9e3188 (patch) | |
tree | 9922689458e6446a82e0f2ad067a543ccf7e3ff3 /Lib/asyncio | |
parent | 5e2746d6e2fb0da29225ead7135f078c5f087b57 (diff) | |
download | cpython-41178e41995992bbe417f94bce158de93f9e3188.zip cpython-41178e41995992bbe417f94bce158de93f9e3188.tar.gz cpython-41178e41995992bbe417f94bce158de93f9e3188.tar.bz2 |
GH-106684: raise `ResourceWarning` when `asyncio.StreamWriter` is not closed (#107650)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/streams.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py index bf15f51..b7ad365 100644 --- a/Lib/asyncio/streams.py +++ b/Lib/asyncio/streams.py @@ -5,6 +5,7 @@ __all__ = ( import collections import socket import sys +import warnings import weakref if hasattr(socket, 'AF_UNIX'): @@ -392,6 +393,11 @@ class StreamWriter: self._transport = new_transport protocol._replace_writer(self) + def __del__(self, warnings=warnings): + if not self._transport.is_closing(): + self.close() + warnings.warn(f"unclosed {self!r}", ResourceWarning) + class StreamReader: |