[Python-Dev] Combining the best of PEP 288 and PEP 325: generator exceptions and cleanup

Phillip J. Eby pje at telecommunity.com
Thu May 19 20:00:15 CEST 2005


At 10:48 AM 5/19/2005 -0700, Guido van Rossum wrote:
>Hm. The way I see it, as soon as a generator raises an exception, its
>frame is part of a cycle: the frame's f_exc_traceback points to the
>traceback object, and the traceback object's tb_frame points back to
>the frame. So that's a cycle right there.

But that cycle doesn't include the generator-iterator object, and it's not 
a collectable cycle while the iterator still lives.  Once the iterator 
itself goes away, that frame cycle is collectable.

However, Tim's new post brings up a different issue: if the collector can't 
tell the difference between a cycle participant and an object that's only 
reachable from a cycle, then the mere existence of a generator __del__ will 
prevent the cycle collection of the entire traceback/frame system that 
includes a generator-iterator reference anywhere!  And that's a pretty 
serious problem.



More information about the Python-Dev mailing list