[Python-3000] Exception tracebacks living too long in 3.0

Antoine Pitrou solipsis at pitrou.net
Sat Mar 29 13:51:28 CET 2008


Hi Jeffrey,

> I had thought that exc_info was
> automatically cleared at the end of any except block that caught an
> exception, but apparently that isn't the case. Is this a bug in 3.0,
> or do we need to keep sys.exc_clear() around?

The explanation seems to be that, while exc_info is cleared immediately, the
thread state exception fields are only cleaned up at the end of
PyEval_EvalFrameEx. The following patch fixes it for me:

diff -r adc2f5003ea3 Python/ceval.c
--- a/Python/ceval.c	Sat Mar 29 06:06:52 2008 +0100
+++ b/Python/ceval.c	Sat Mar 29 13:46:27 2008 +0100
@@ -1477,6 +1477,12 @@ PyEval_EvalFrameEx(PyFrameObject *f, int
 					"'finally' pops bad exception");
 				why = WHY_EXCEPTION;
 			}
+			if (tstate->frame->f_exc_type != NULL)
+				reset_exc_info(tstate);
+			else {
+				assert(tstate->frame->f_exc_value == NULL);
+				assert(tstate->frame->f_exc_traceback == NULL);
+			}
 			Py_DECREF(v);
 			break;


Regards

Antoine.




More information about the Python-3000 mailing list