From a85a1d337d26a65036e427341d15e3979f7e9ced Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 28 May 2019 16:01:17 +0200 Subject: 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. --- Python/pythonrun.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Python/pythonrun.c') diff --git a/Python/pythonrun.c b/Python/pythonrun.c index ba1d1cf02f..ace9f2f987 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -978,6 +978,16 @@ _PyErr_Display(PyObject *file, PyObject *exception, PyObject *value, PyObject *t } 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 -- cgit v1.2.1