Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Python/errors.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,6 +26,7 @@ extern "C" {

_Py_IDENTIFIER(builtins);
_Py_IDENTIFIER(stderr);
_Py_IDENTIFIER(flush);


/* Forward declarations */
Expand DownExpand Up@@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions Python/pythonrun.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down