Skip to content
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: io.IOBase destructor logs close() exceptions
In development mode (-X dev) and in debug build, the io.IOBase
destructor now logs close() exceptions. These exceptions are silent
by default in release mode.
  • Loading branch information
vstinner committed Apr 12, 2019
commit b029db68dc3758d865d4328af94e2e67c12a9da8
4 changes: 3 additions & 1 deletion Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ Miscellaneous options
* Enable :ref:`asyncio debug mode <asyncio-debug-mode>`.
* Set the :attr:`~sys.flags.dev_mode` attribute of :attr:`sys.flags` to
``True``
* :class:`io.IOBase` destructor logs ``close()`` exceptions.

* ``-X utf8`` enables UTF-8 mode for operating system interfaces, overriding
the default locale-aware mode. ``-X utf8=0`` explicitly disables UTF-8
Expand Down Expand Up @@ -465,7 +466,8 @@ Miscellaneous options
The ``-X importtime``, ``-X dev`` and ``-X utf8`` options.

.. versionadded:: 3.8
The ``-X pycache_prefix`` option.
The ``-X pycache_prefix`` option. The ``-X dev`` option now logs
``close()`` exceptions in :class:`io.IOBase` destructor.


Options you shouldn't use
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
In development mode (:option:`-X` ``dev``) and in debug build, the
:class:`io.IOBase` destructor now logs ``close()`` exceptions. These exceptions
are silent by default in release mode.
18 changes: 15 additions & 3 deletions Modules/_io/iobase.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,22 @@ iobase_finalize(PyObject *self)
/* 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)
PyErr_Clear();
else
if (res == NULL) {
#ifndef Py_DEBUG
const _PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
if (config->dev_mode) {
PyErr_WriteUnraisable(self);
}
else {
PyErr_Clear();
}
#else
PyErr_WriteUnraisable(self);
#endif
}
else {
Py_DECREF(res);
}
}

/* Restore the saved exception. */
Expand Down