Amaury Forgeot d'Arc <amaur...@gmail.com> added the comment:

Is it normal that even after the call to next(), the generator frame contains a 
reference to the RuntimeError?

Long explanation:
- When the function exits, there is a cycle [parent frame]-> ['it' variable]-> 
[generator frame]-> [RuntimeError]-> [parent frame].
- gc.collect() collects them all, destroys the generator, this causes 
GeneratorExit exception to be sent into the generator frame.
- 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.
- The exception is resurrected, but this does not prevent the gc from calling 
its tp_clear method! and setting exc_info() as a side-effect of gc.collect() is 
really weird...

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue7173>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to