Message339194
| Author |
ncoghlan |
| Recipients |
Windson Yang, ncoghlan, pitrou |
| Date |
2019年03月30日.12:39:58 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1553949598.78.0.775815340313.issue14934@roundup.psfhosted.org> |
| In-reply-to |
| Content |
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? |
|
History
|
|---|
| 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 |
|