diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-04-12 15:06:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-12 15:06:47 (GMT) |
commit | 44235041f3b957abd36d3792450c3540aa09e120 (patch) | |
tree | f5a07219352053068a742e62bd75447c22e50aa5 /Modules | |
parent | 9d949f7796da612f1b588d18c6f041376992a9fc (diff) | |
download | cpython-44235041f3b957abd36d3792450c3540aa09e120.zip cpython-44235041f3b957abd36d3792450c3540aa09e120.tar.gz cpython-44235041f3b957abd36d3792450c3540aa09e120.tar.bz2 |
bpo-18748: io.IOBase destructor now logs close() errors in dev mode (GH-12786)
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.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_io/iobase.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 9b063cd..3a8f16a 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -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. */ |