8000 [3.8] bpo-37223: test_io: silence destructor errors by vstinner · Pull Request #14031 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.8] bpo-37223: test_io: silence destructor errors #14031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.

(cherry picked from commit 4f6f7c5)
  • Loading branch information
vstinner committed Jun 12, 2019
commit c7c65823ad3bf5b6b823b9c7370768ec1c0720ef
10 changes: 10 additions & 0 deletions Lib/_pyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,16 @@ def close(self):

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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:class:`_pyio.IOBase` destructor now does nothing if getting the ``closed``
attribute fails to better mimick :class:`_io.IOBase` finalizer.
0