Skip to content

Commit

Permalink
gh-62948: IOBase finalizer logs close() exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed May 30, 2023
1 parent 4b65d56 commit 56d73b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
9 changes: 9 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ New Modules
Improved Modules
================

io
--

The :class:`io.IOBase` finalizer now logs the ``close()`` method errors with
:data:`sys.excepthook`. Previously, errors were ignored silently by default,
and only logged in :ref:`Python Development Mode <devmode>` or on :ref:`Python
built on debug mode <debug-build>`.
(Contributed by Victor Stinner in :gh:`62948`.)

pathlib
-------

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The :class:`io.IOBase` finalizer now logs the ``close()`` method errors with
:data:`sys.excepthook`. Previously, errors were ignored silently by default,
and only logged in :ref:`Python Development Mode <devmode>` or on
:ref:`Python built on debug mode <debug-build>`. Patch by Victor Stinner.
12 changes: 0 additions & 12 deletions Modules/_io/iobase.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,20 +319,8 @@ iobase_finalize(PyObject *self)
if (PyObject_SetAttr(self, &_Py_ID(_finalizing), Py_True))
PyErr_Clear();
res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(close));
/* Silencing I/O errors is bad, but printing spurious tracebacks is
equally as bad, and potentially more frequent (because of
shutdown issues). */
if (res == NULL) {
#ifndef Py_DEBUG
if (_Py_GetConfig()->dev_mode) {
PyErr_WriteUnraisable(self);
}
else {
PyErr_Clear();
}
#else
PyErr_WriteUnraisable(self);
#endif
}
else {
Py_DECREF(res);
Expand Down

0 comments on commit 56d73b9

Please sign in to comment.