From 41178e41995992bbe417f94bce158de93f9e3188 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Sat, 5 Aug 2023 17:48:15 +0530 Subject: GH-106684: raise `ResourceWarning` when `asyncio.StreamWriter` is not closed (#107650) --- Lib/asyncio/streams.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Lib/asyncio/streams.py') diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py index bf15f517e50..b7ad365709b 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: -- cgit v1.2.3