Skip to content

Commit 56d73b9

Browse files
committed
gh-62948: IOBase finalizer logs close() exceptions
1 parent 4b65d56 commit 56d73b9

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

Doc/whatsnew/3.13.rst

+9
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ New Modules
8787
Improved Modules
8888
================
8989

90+
io
91+
--
92+
93+
The :class:`io.IOBase` finalizer now logs the ``close()`` method errors with
94+
:data:`sys.excepthook`. Previously, errors were ignored silently by default,
95+
and only logged in :ref:`Python Development Mode <devmode>` or on :ref:`Python
96+
built on debug mode <debug-build>`.
97+
(Contributed by Victor Stinner in :gh:`62948`.)
98+
9099
pathlib
91100
-------
92101

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The :class:`io.IOBase` finalizer now logs the ``close()`` method errors with
2+
:data:`sys.excepthook`. Previously, errors were ignored silently by default,
3+
and only logged in :ref:`Python Development Mode <devmode>` or on
4+
:ref:`Python built on debug mode <debug-build>`. Patch by Victor Stinner.

Modules/_io/iobase.c

-12
Original file line numberDiff line numberDiff line change
@@ -319,20 +319,8 @@ iobase_finalize(PyObject *self)
319319
if (PyObject_SetAttr(self, &_Py_ID(_finalizing), Py_True))
320320
PyErr_Clear();
321321
res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(close));
322-
/* Silencing I/O errors is bad, but printing spurious tracebacks is
323-
equally as bad, and potentially more frequent (because of
324-
shutdown issues). */
325322
if (res == NULL) {
326-
#ifndef Py_DEBUG
327-
if (_Py_GetConfig()->dev_mode) {
328-
PyErr_WriteUnraisable(self);
329-
}
330-
else {
331-
PyErr_Clear();
332-
}
333-
#else
334323
PyErr_WriteUnraisable(self);
335-
#endif
336324
}
337325
else {
338326
Py_DECREF(res);

0 commit comments

Comments
 (0)