Nick Coghlan <ncogh...@gmail.com> added the comment:
If I recall correctly, it's the generator destructor that handles throwing in ``GeneratorExit`` to get the generator to terminate. So this code can resurrect a generator as it's being collected by the GC: def resurrecting(resurrected): self = yield try: yield finally: resurrected.append(self) storage = [] g = resurrecting(storage) g.send(g) # Give the generator a reference to itself del g # Now the generator is in a cycle with itself gc.collect() gc.collect() gc.collect() # Generator has been added to the storage instead of collected assert len(storage) == 1 # Clear the storage to kill it for real this time storage.clear() # Weakrefs shouldn't get called until here Antoine, does that sound right to you? ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue14934> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com