Message339194
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? |
|
Date |
User |
Action |
Args |
2019-03-30 12:39:58 | ncoghlan | set | recipients:
+ ncoghlan, pitrou, Windson Yang |
2019-03-30 12:39:58 | ncoghlan | set | messageid: <1553949598.78.0.775815340313.issue14934@roundup.psfhosted.org> |
2019-03-30 12:39:58 | ncoghlan | link | issue14934 messages |
2019-03-30 12:39:58 | ncoghlan | create | |
|