summaryrefslogtreecommitdiffstats
path: root/Lib/_pyio.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r--Lib/_pyio.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index 43c2434..0b6493b 100644
--- a/Lib/_pyio.py
+++ b/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: