diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-01-10 10:24:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-10 10:24:40 (GMT) |
commit | fb2c3465f09e1f720cdae7eca87d62125a327fd9 (patch) | |
tree | a1cfdcf7ea81295f3a955bcdec2275b8e8967965 /Lib/asyncio/base_subprocess.py | |
parent | 9b07681c09182d4b9d23cd52566a4992b8afecbb (diff) | |
download | cpython-fb2c3465f09e1f720cdae7eca87d62125a327fd9.zip cpython-fb2c3465f09e1f720cdae7eca87d62125a327fd9.tar.gz cpython-fb2c3465f09e1f720cdae7eca87d62125a327fd9.tar.bz2 |
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.
Diffstat (limited to 'Lib/asyncio/base_subprocess.py')
-rw-r--r-- | Lib/asyncio/base_subprocess.py | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/asyncio/base_subprocess.py b/Lib/asyncio/base_subprocess.py index b547c44..f503f78 100644 --- a/Lib/asyncio/base_subprocess.py +++ b/Lib/asyncio/base_subprocess.py @@ -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): |