Solve issue 1400 at least in part -- whenever we run Python code, at the end

we also flush stderr and stdout.  (XXX this may override errors if there's a problem
flushing.)
This commit is contained in:
Guido van Rossum 2007-12-05 05:14:58 +00:00
parent 48dc27c040
commit 6c193fa09d
1 changed files with 24 additions and 0 deletions

View File

@ -1442,6 +1442,28 @@ PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals,
return ret; return ret;
} }
static void
flush_io(void)
{
PyObject *f, *r;
f = PySys_GetObject("stderr");
if (f != NULL) {
r = PyObject_CallMethod(f, "flush", "");
if (r)
Py_DECREF(r);
else
PyErr_Clear();
}
f = PySys_GetObject("stdout");
if (f != NULL) {
r = PyObject_CallMethod(f, "flush", "");
if (r)
Py_DECREF(r);
else
PyErr_Clear();
}
}
static PyObject * static PyObject *
run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals, run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals,
PyCompilerFlags *flags, PyArena *arena) PyCompilerFlags *flags, PyArena *arena)
@ -1453,6 +1475,7 @@ run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals,
return NULL; return NULL;
v = PyEval_EvalCode(co, globals, locals); v = PyEval_EvalCode(co, globals, locals);
Py_DECREF(co); Py_DECREF(co);
flush_io();
return v; return v;
} }
@ -1485,6 +1508,7 @@ run_pyc_file(FILE *fp, const char *filename, PyObject *globals,
if (v && flags) if (v && flags)
flags->cf_flags |= (co->co_flags & PyCF_MASK); flags->cf_flags |= (co->co_flags & PyCF_MASK);
Py_DECREF(co); Py_DECREF(co);
flush_io();
return v; return v;
} }