mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-18748: Fix _pyio.IOBase destructor (closed case) (GH-13952)
_pyio.IOBase destructor now does nothing if getting the closed attribute fails to better mimick _io.IOBase finalizer.
This commit is contained in:
parent
8a8b59c979
commit
4f6f7c5a61
2 changed files with 12 additions and 0 deletions
10
Lib/_pyio.py
10
Lib/_pyio.py
|
@ -405,6 +405,16 @@ class IOBase(metaclass=abc.ABCMeta):
|
|||
|
||||
def __del__(self):
|
||||
"""Destructor. Calls close()."""
|
||||
try:
|
||||
closed = self.closed
|
||||
except Exception:
|
||||
# If getting closed fails, then the object is probably
|
||||
# in an unusable state, so ignore.
|
||||
return
|
||||
|
||||
if closed:
|
||||
return
|
||||
|
||||
if _IOBASE_EMITS_UNRAISABLE:
|
||||
self.close()
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue