From fb2c3465f09e1f720cdae7eca87d62125a327fd9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 10 Jan 2019 11:24:40 +0100 Subject: asyncio: __del__() keep reference to warnings.warn (GH-11491) * asyncio: __del__() keep reference to warnings.warn The __del__() methods of asyncio classes now keep a strong reference to the warnings.warn() to be able to display the ResourceWarning warning in more cases. Ensure that the function remains available if instances are destroyed late during Python shutdown (while module symbols are cleared). * Rename warn parameter to _warn "_warn" name is a hint that it's not the regular warnings.warn() function. --- Lib/asyncio/sslproto.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Lib/asyncio/sslproto.py') diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py index 12fdb0d1c5..42785609dc 100644 --- a/Lib/asyncio/sslproto.py +++ b/Lib/asyncio/sslproto.py @@ -316,10 +316,9 @@ class _SSLProtocolTransport(transports._FlowControlMixin, self._closed = True self._ssl_protocol._start_shutdown() - def __del__(self): + def __del__(self, _warn=warnings.warn): if not self._closed: - warnings.warn(f"unclosed transport {self!r}", ResourceWarning, - source=self) + _warn(f"unclosed transport {self!r}", ResourceWarning, source=self) self.close() def is_reading(self): -- cgit v1.2.1