diff Python/pythonrun.c @ 61654:f3f95ed82744

handle_system_exit() flushs files to warranty the output order PyObject_Print() writes into the C object stderr, whereas PySys_WriteStderr() writes into the Python object sys.stderr. Each object has its own buffer, so call sys.stderr.flush() and fflush(stderr).
author Victor Stinner <victor.stinner@haypocalc.com>
date Mon, 17 May 2010 08:58:51 +0000
parents 47b4da86b9b9
children 942b3c168f15
line wrap: on
line diff
--- a/Python/pythonrun.c	Mon May 17 01:26:01 2010 +0000
+++ b/Python/pythonrun.c	Mon May 17 08:58:51 2010 +0000
@@ -1367,7 +1367,11 @@
     if (PyLong_Check(value))
         exitcode = (int)PyLong_AsLong(value);
     else {
+        PyObject *sys_stderr = PySys_GetObject("stderr");
+        if (sys_stderr != NULL)
+            PyObject_CallMethod(sys_stderr, "flush", NULL);
         PyObject_Print(value, stderr, Py_PRINT_RAW);
+        fflush(stderr);
         PySys_WriteStderr("\n");
         exitcode = 1;
     }