diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-28 14:01:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-28 14:01:17 (GMT) |
commit | a85a1d337d26a65036e427341d15e3979f7e9ced (patch) | |
tree | b355ad22fb8ca020f6572c48519e2fdf641db47a /Python/errors.c | |
parent | 51ddab8dae056867f3595ab3400bffc93f67c8d4 (diff) | |
download | cpython-a85a1d337d26a65036e427341d15e3979f7e9ced.zip cpython-a85a1d337d26a65036e427341d15e3979f7e9ced.tar.gz cpython-a85a1d337d26a65036e427341d15e3979f7e9ced.tar.bz2 |
bpo-36829: sys.excepthook and sys.unraisablehook flush (GH-13620)
sys.excepthook() and sys.unraisablehook() now explicitly flush the
file (usually sys.stderr).
If file.flush() fails, sys.excepthook() silently ignores the error,
whereas sys.unraisablehook() logs the new exception.
Diffstat (limited to 'Python/errors.c')
-rw-r--r-- | Python/errors.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c index bd33d4d..8a94afd 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -26,6 +26,7 @@ extern "C" { _Py_IDENTIFIER(builtins); _Py_IDENTIFIER(stderr); +_Py_IDENTIFIER(flush); /* Forward declarations */ @@ -1254,6 +1255,14 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type, if (PyFile_WriteString("\n", file) < 0) { return -1; } + + /* Explicitly call file.flush() */ + PyObject *res = _PyObject_CallMethodId(file, &PyId_flush, NULL); + if (!res) { + return -1; + } + Py_DECREF(res); + return 0; } |