comparison Python/pythonrun.c @ 63849:55397533da51 2.7

sys.stderr and sys.excepthook can be None at interpreter shutdown, in which case display the appropriate error message. (part of #5319)
author Antoine Pitrou <solipsis@pitrou.net>
date Sun, 08 Aug 2010 21:37:51 +0000
parents bd5f5df7ed78
children a4a27240fe09
comparison
equal deleted inserted replaced
63848:55c70e79c688 63849:55397533da51
1147 PySys_SetObject("last_type", exception); 1147 PySys_SetObject("last_type", exception);
1148 PySys_SetObject("last_value", v); 1148 PySys_SetObject("last_value", v);
1149 PySys_SetObject("last_traceback", tb); 1149 PySys_SetObject("last_traceback", tb);
1150 } 1150 }
1151 hook = PySys_GetObject("excepthook"); 1151 hook = PySys_GetObject("excepthook");
1152 if (hook) { 1152 if (hook && hook != Py_None) {
1153 PyObject *args = PyTuple_Pack(3, 1153 PyObject *args = PyTuple_Pack(3,
1154 exception, v, tb ? tb : Py_None); 1154 exception, v, tb ? tb : Py_None);
1155 PyObject *result = PyEval_CallObject(hook, args); 1155 PyObject *result = PyEval_CallObject(hook, args);
1156 if (result == NULL) { 1156 if (result == NULL) {
1157 PyObject *exception2, *v2, *tb2; 1157 PyObject *exception2, *v2, *tb2;
1197 PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) 1197 PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
1198 { 1198 {
1199 int err = 0; 1199 int err = 0;
1200 PyObject *f = PySys_GetObject("stderr"); 1200 PyObject *f = PySys_GetObject("stderr");
1201 Py_INCREF(value); 1201 Py_INCREF(value);
1202 if (f == NULL) 1202 if (f == NULL || f == Py_None)
1203 fprintf(stderr, "lost sys.stderr\n"); 1203 fprintf(stderr, "lost sys.stderr\n");
1204 else { 1204 else {
1205 if (Py_FlushLine()) 1205 if (Py_FlushLine())
1206 PyErr_Clear(); 1206 PyErr_Clear();
1207 fflush(stdout); 1207 fflush(stdout);