diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-06-11 00:49:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-11 00:49:06 (GMT) |
commit | 4f6f7c5a611905fb6b81671547f268c226bc646a (patch) | |
tree | d5c62b12768c6450f7537fb28a9b87e1bee6f9ea /Lib/_pyio.py | |
parent | 8a8b59c9794674b50b2242698c29038034f4864c (diff) | |
download | cpython-4f6f7c5a611905fb6b81671547f268c226bc646a.zip cpython-4f6f7c5a611905fb6b81671547f268c226bc646a.tar.gz cpython-4f6f7c5a611905fb6b81671547f268c226bc646a.tar.bz2 |
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.
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r-- | Lib/_pyio.py | 10 |
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: |