mirror of
https://github.com/python/cpython.git
synced 2025-08-08 19:09:46 +00:00
[3.12] gh-109538: Catch closed loop runtime error and issue warning (GH-111983) (#112142)
* [3.12] gh-109538: Avoid RuntimeError when StreamWriter is deleted with closed loop (GH-111983) Issue a ResourceWarning instead. (cherry picked from commite0f5127975
) gh-109538: Avoid RuntimeError when StreamWriter is deleted with closed loop (#111983) Issue a ResourceWarning instead. Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> (cherry picked from commite0f5127975
) * Fix missing warnings import
This commit is contained in:
parent
3f2cdbe666
commit
2ef3676a5b
3 changed files with 66 additions and 2 deletions
|
@ -5,6 +5,7 @@ __all__ = (
|
|||
import collections
|
||||
import socket
|
||||
import sys
|
||||
import warnings
|
||||
import weakref
|
||||
|
||||
if hasattr(socket, 'AF_UNIX'):
|
||||
|
@ -405,8 +406,11 @@ class StreamWriter:
|
|||
|
||||
def __del__(self):
|
||||
if not self._transport.is_closing():
|
||||
self.close()
|
||||
|
||||
if self._loop.is_closed():
|
||||
warnings.warn("loop is closed", ResourceWarning)
|
||||
else:
|
||||
self.close()
|
||||
warnings.warn(f"unclosed {self!r}", ResourceWarning)
|
||||
|
||||
class StreamReader:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue