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.
_Py_IDENTIFIER(builtins);
_Py_IDENTIFIER(stderr);
+_Py_IDENTIFIER(flush);
/* Forward declarations */
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;
}
}
print_exception_recursive(file, value, seen);
Py_XDECREF(seen);
+
+ /* Call file.flush() */
+ PyObject *res = _PyObject_CallMethodId(file, &PyId_flush, NULL);
+ if (!res) {
+ /* Silently ignore file.flush() error */
+ PyErr_Clear();
+ }
+ else {
+ Py_DECREF(res);
+ }
}
void