[issue12791] reference cycle with exception state not broken by generator.close()

Antoine Pitrou report at bugs.python.org
Sat Aug 20 13:46:37 CEST 2011


Antoine Pitrou <pitrou at free.fr> added the comment:

The problem is probably that the frame keeps the last execution state around, and since the exception itself has a reference to a frame, a cycle is created. Note that it doesn't happen if you catch the GeneratorExit that gets raised inside the generator at shutdown:

def leaky_generator():
    try:   
        1/0
    except:  # Exception handler with anonymous exception variable
        try:
            yield  # Yield from exception handler
        except (GeneratorExit, RuntimeError):
            pass

def throw_leaks(g):
    try:
        g.throw(RuntimeError())
    except Exception:
        pass

----------
nosy: +benjamin.peterson, ncoghlan
title: Yield" leaks exception being handled as garbage -> reference cycle with exception state not broken by generator.close()
versions: +Python 3.3 -Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12791>
_______________________________________


More information about the Python-bugs-list mailing list