Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 44162:ef5399b353c9
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.)
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 05 Dec 2007 05:14:58 +0000 |
| parents | e08b12c3b913 |
| children | 5a0cbe36a603 |
comparison
equal
deleted
inserted
replaced
| 44161:1a7dfb61b4d8 | 44162:ef5399b353c9 |
|---|---|
| 1440 ret = run_mod(mod, filename, globals, locals, flags, arena); | 1440 ret = run_mod(mod, filename, globals, locals, flags, arena); |
| 1441 PyArena_Free(arena); | 1441 PyArena_Free(arena); |
| 1442 return ret; | 1442 return ret; |
| 1443 } | 1443 } |
| 1444 | 1444 |
| 1445 static void | |
| 1446 flush_io(void) | |
| 1447 { | |
| 1448 PyObject *f, *r; | |
| 1449 f = PySys_GetObject("stderr"); | |
| 1450 if (f != NULL) { | |
| 1451 r = PyObject_CallMethod(f, "flush", ""); | |
| 1452 if (r) | |
| 1453 Py_DECREF(r); | |
| 1454 else | |
| 1455 PyErr_Clear(); | |
| 1456 } | |
| 1457 f = PySys_GetObject("stdout"); | |
| 1458 if (f != NULL) { | |
| 1459 r = PyObject_CallMethod(f, "flush", ""); | |
| 1460 if (r) | |
| 1461 Py_DECREF(r); | |
| 1462 else | |
| 1463 PyErr_Clear(); | |
| 1464 } | |
| 1465 } | |
| 1466 | |
| 1445 static PyObject * | 1467 static PyObject * |
| 1446 run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals, | 1468 run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals, |
| 1447 PyCompilerFlags *flags, PyArena *arena) | 1469 PyCompilerFlags *flags, PyArena *arena) |
| 1448 { | 1470 { |
| 1449 PyCodeObject *co; | 1471 PyCodeObject *co; |
| 1451 co = PyAST_Compile(mod, filename, flags, arena); | 1473 co = PyAST_Compile(mod, filename, flags, arena); |
| 1452 if (co == NULL) | 1474 if (co == NULL) |
| 1453 return NULL; | 1475 return NULL; |
| 1454 v = PyEval_EvalCode(co, globals, locals); | 1476 v = PyEval_EvalCode(co, globals, locals); |
| 1455 Py_DECREF(co); | 1477 Py_DECREF(co); |
| 1478 flush_io(); | |
| 1456 return v; | 1479 return v; |
| 1457 } | 1480 } |
| 1458 | 1481 |
| 1459 static PyObject * | 1482 static PyObject * |
| 1460 run_pyc_file(FILE *fp, const char *filename, PyObject *globals, | 1483 run_pyc_file(FILE *fp, const char *filename, PyObject *globals, |
| 1483 co = (PyCodeObject *)v; | 1506 co = (PyCodeObject *)v; |
| 1484 v = PyEval_EvalCode(co, globals, locals); | 1507 v = PyEval_EvalCode(co, globals, locals); |
| 1485 if (v && flags) | 1508 if (v && flags) |
| 1486 flags->cf_flags |= (co->co_flags & PyCF_MASK); | 1509 flags->cf_flags |= (co->co_flags & PyCF_MASK); |
| 1487 Py_DECREF(co); | 1510 Py_DECREF(co); |
| 1511 flush_io(); | |
| 1488 return v; | 1512 return v; |
| 1489 } | 1513 } |
| 1490 | 1514 |
| 1491 PyObject * | 1515 PyObject * |
| 1492 Py_CompileStringFlags(const char *str, const char *filename, int start, | 1516 Py_CompileStringFlags(const char *str, const char *filename, int start, |
