mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
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.
This commit is contained in:
parent
51ddab8dae
commit
a85a1d337d
2 changed files with 19 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue