8000 flush_io too · python/cpython@86af53f · GitHub
[go: up one dir, main page]

Skip to content

Commit 86af53f

Browse files
committed
flush_io too
1 parent d220a9f commit 86af53f

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

Python/pythonrun.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,35 +1639,29 @@ PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals,
16391639

16401640
}
16411641

1642-
16431642
static void
1644-
flush_io(void)
1643+
flush_io_stream(PyThreadState *tstate, PyObject *name)
16451644
{
1646-
PyObject *f, *r;
1647-
PyObject *type, *value, *traceback;
1648-
1649-
/* Save the current exception */
1650-
PyErr_Fetch(&type, &value, &traceback);
1651-
1652-
PyThreadState *tstate = _PyThreadState_GET();
1653-
f = _PySys_GetAttr(tstate, &_Py_ID(stderr));
1654-
if (f != NULL) {
1655-
r = _PyObject_CallMethodNoArgs(f, &_Py_ID(flush));
1656-
if (r)
1657-
Py_DECREF(r);
1658-
else
1659-
PyErr_Clear();
1660-
}
1661-
f = _PySys_GetAttr(tstate, &_Py_ID(stdout));
1645+
PyObject *f = _PySys_GetAttr(tstate, &_Py_ID(stderr));
16621646
if (f != NULL) {
1663-
r = _PyObject_CallMethodNoArgs(f, &_Py_ID(flush));
1664-
if (r)
1647+
PyObject *r = _PyObject_CallMethodNoArgs(f, &_Py_ID(flush));
1648+
if (r) {
16651649
Py_DECREF(r);
1666-
else
1650+
}
1651+
else {
16671652
PyErr_Clear();
1653+
}
16681654
}
1655+
}
16691656

1670-
PyErr_Restore(type, value, traceback);
1657+
static void
1658+
flush_io(void)
1659+
{
1660+
PyThreadState *tstate = _PyThreadState_GET();
1661+
PyObject *exc = _PyErr_GetRaisedException(tstate);
1662+
flush_io_stream(tstate, &_Py_ID(stderr));
1663+
flush_io_stream(tstate, &_Py_ID(stdout));
1664+
_PyErr_SetRaisedException(tstate, exc);
16711665
}
16721666

16731667
static PyObject *

0 commit comments

Comments
 (0)
0