mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
gh-62948: IOBase finalizer logs close() errors (#105104)
This commit is contained in:
parent
85e5d03163
commit
58a2e09816
5 changed files with 19 additions and 40 deletions
20
Lib/_pyio.py
20
Lib/_pyio.py
|
|
@ -33,11 +33,8 @@
|
|||
# Rebind for compatibility
|
||||
BlockingIOError = BlockingIOError
|
||||
|
||||
# Does io.IOBase finalizer log the exception if the close() method fails?
|
||||
# The exception is ignored silently by default in release build.
|
||||
_IOBASE_EMITS_UNRAISABLE = (hasattr(sys, "gettotalrefcount") or sys.flags.dev_mode)
|
||||
# Does open() check its 'errors' argument?
|
||||
_CHECK_ERRORS = _IOBASE_EMITS_UNRAISABLE
|
||||
_CHECK_ERRORS = (hasattr(sys, "gettotalrefcount") or sys.flags.dev_mode)
|
||||
|
||||
|
||||
def text_encoding(encoding, stacklevel=2):
|
||||
|
|
@ -416,18 +413,9 @@ def __del__(self):
|
|||
if closed:
|
||||
return
|
||||
|
||||
if _IOBASE_EMITS_UNRAISABLE:
|
||||
self.close()
|
||||
else:
|
||||
# The try/except block is in case this is called at program
|
||||
# exit time, when it's possible that globals have already been
|
||||
# deleted, and then the close() call might fail. Since
|
||||
# there's nothing we can do about such failures and they annoy
|
||||
# the end users, we suppress the traceback.
|
||||
try:
|
||||
self.close()
|
||||
except:
|
||||
pass
|
||||
# If close() fails, the caller logs the exception with
|
||||
# sys.unraisablehook. close() must be called at the end at __del__().
|
||||
self.close()
|
||||
|
||||
### Inquiries ###
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue