summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-07-09 15:04:50 (GMT)
committerGuido van Rossum <guido@python.org>2007-07-09 15:04:50 (GMT)
commite8432ac42f9030bd75de03a07fd9059006292b7a (patch)
treeeda26cd19a1646b0c59a03f53a5c0b17b6097109 /Python/pythonrun.c
parent5ed033b5a21d56db0dbb0b2535b83afd5cad143d (diff)
downloadcpython-e8432ac42f9030bd75de03a07fd9059006292b7a.zip
cpython-e8432ac42f9030bd75de03a07fd9059006292b7a.tar.gz
cpython-e8432ac42f9030bd75de03a07fd9059006292b7a.tar.bz2
Upon exit, flush stdout and stderr (twice: before and after the code that
attempts to delete all modules). This makes test_subprocess work again. (I can't quite figure out why stdout/stderr don't get deleted properly, which would flush them anyway, but that's a separate issue.)
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index db21daf..d8bc646 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -291,6 +291,32 @@ Py_Initialize(void)
extern void dump_counts(FILE*);
#endif
+/* Flush stdout and stderr */
+
+void
+flush_std_files()
+{
+ PyObject *fout = PySys_GetObject("stdout");
+ PyObject *ferr = PySys_GetObject("stderr");
+ PyObject *tmp;
+
+ if (fout != NULL) {
+ tmp = PyObject_CallMethod(fout, "flush", "");
+ if (tmp == NULL)
+ PyErr_Clear();
+ else
+ Py_DECREF(tmp);
+ }
+
+ if (ferr != NULL) {
+ tmp = PyObject_CallMethod(ferr, "flush", "");
+ if (tmp == NULL)
+ PyErr_Clear();
+ else
+ Py_DECREF(tmp);
+ }
+}
+
/* Undo the effect of Py_Initialize().
Beware: if multiple interpreter and/or thread states exist, these
@@ -326,6 +352,9 @@ Py_Finalize(void)
call_py_exitfuncs();
initialized = 0;
+ /* Flush stdout+stderr */
+ flush_std_files();
+
/* Get current thread state and interpreter pointer */
tstate = PyThreadState_GET();
interp = tstate->interp;
@@ -361,6 +390,9 @@ Py_Finalize(void)
/* Destroy all modules */
PyImport_Cleanup();
+ /* Flush stdout+stderr (again, in case more was printed) */
+ flush_std_files();
+
/* Collect final garbage. This disposes of cycles created by
* new-style class definitions, for example.
* XXX This is disabled because it caused too many problems. If