Antoine Pitrou <[email protected]> added the comment:
> Is it normal that even after the call to next(), the generator frame
> contains a reference to the RuntimeError?
As long as it's executing the generator it's quite normal. The generator must
be able to restore the caller's RuntimeError when interrupted by a yield. But
after the yield, the generator normally doesn't retain a reference (thanks to
SWAP_EXC_STATE() in YIELD_VALUE).
> - This executes SWAP_EXC_STATE() in ceval.c ("/* We were in an except handler
> when we left, restore the exception state which was put aside */"), this
> *moves* the reference to the exception from the frame to the thread state.
Actually, it (does/should) execute SAVE_EXC_STATE() instead, because the
thread's exception state was empty when yielding.
The following patch seems to do the trick:
diff -r 4465a45b8876 Python/ceval.c
--- a/Python/ceval.c Mon Feb 15 09:35:16 2010 +0100
+++ b/Python/ceval.c Mon Feb 15 20:51:58 2010 +0100
@@ -1159,7 +1159,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int
assert(stack_pointer != NULL);
f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */
- if (f->f_code->co_flags & CO_GENERATOR) {
+ if (!throwflag && (f->f_code->co_flags & CO_GENERATOR)) {
if (f->f_exc_type != NULL && f->f_exc_type != Py_None) {
/* We were in an except handler when we left,
restore the exception state which was put aside
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue7173>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com