]> granicus.if.org Git - python/commitdiff
bpo-18748: Fix _pyio.IOBase destructor (closed case) (GH-13952)
authorVictor Stinner <vstinner@redhat.com>
Tue, 11 Jun 2019 00:49:06 +0000 (02:49 +0200)
committerGitHub <noreply@github.com>
Tue, 11 Jun 2019 00:49:06 +0000 (02:49 +0200)
_pyio.IOBase destructor now does nothing if getting the closed
attribute fails to better mimick _io.IOBase finalizer.

Lib/_pyio.py
Misc/NEWS.d/next/Library/2019-06-11-01-54-19.bpo-18748.ADqCkq.rst [new file with mode: 0644]

index 43c24342ad6162ce97bc93a20fd105a3500c5f1e..0b6493bc8dc926281803f955c4eb99c358512ce7 100644 (file)
@@ -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:
diff --git a/Misc/NEWS.d/next/Library/2019-06-11-01-54-19.bpo-18748.ADqCkq.rst b/Misc/NEWS.d/next/Library/2019-06-11-01-54-19.bpo-18748.ADqCkq.rst
new file mode 100644 (file)
index 0000000..295ddeb
--- /dev/null
@@ -0,0 +1,2 @@
+:class:`_pyio.IOBase` destructor now does nothing if getting the ``closed``
+attribute fails to better mimick :class:`_io.IOBase` finalizer.