diff options
author | Guido van Rossum <guido@python.org> | 2007-12-05 05:14:58 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-12-05 05:14:58 (GMT) |
commit | 6c193fa09d38b2eb34a3607381c1cbb495e34d6f (patch) | |
tree | 007834c87b11192cb7df431747fa249f2b998a83 /Python | |
parent | 48dc27c04088c1c048b6b05076b9d36228a5e287 (diff) | |
download | cpython-6c193fa09d38b2eb34a3607381c1cbb495e34d6f.zip cpython-6c193fa09d38b2eb34a3607381c1cbb495e34d6f.tar.gz cpython-6c193fa09d38b2eb34a3607381c1cbb495e34d6f.tar.bz2 |
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.)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pythonrun.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 14fe783..f95ea83 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1442,6 +1442,28 @@ PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals, 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 * run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals, PyCompilerFlags *flags, PyArena *arena) @@ -1453,6 +1475,7 @@ run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals, return NULL; v = PyEval_EvalCode(co, globals, locals); Py_DECREF(co); + flush_io(); return v; } @@ -1485,6 +1508,7 @@ run_pyc_file(FILE *fp, const char *filename, PyObject *globals, if (v && flags) flags->cf_flags |= (co->co_flags & PyCF_MASK); Py_DECREF(co); + flush_io(); return v; } |