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.
This commit is contained in:
@@ -120,10 +120,9 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
|
||||
|
||||
# Don't clear the _proc reference yet: _post_init() may still run
|
||||
|
||||
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 get_pid(self):
|
||||
|
||||
Reference in New Issue
Block a user