Message99370
> 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 |
|
Date |
User |
Action |
Args |
2010-02-15 19:54:40 | pitrou | set | recipients:
+ pitrou, amaury.forgeotdarc, scoder, vstinner, benjamin.peterson, Arfrever |
2010-02-15 19:54:40 | pitrou | set | messageid: <1266263680.31.0.359434818698.issue7173@psf.upfronthosting.co.za> |
2010-02-15 19:54:38 | pitrou | link | issue7173 messages |
2010-02-15 19:54:37 | pitrou | create | |
|