homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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:58ncoghlansetrecipients: + ncoghlan, pitrou, Windson Yang
2019年03月30日 12:39:58ncoghlansetmessageid: <1553949598.78.0.775815340313.issue14934@roundup.psfhosted.org>
2019年03月30日 12:39:58ncoghlanlinkissue14934 messages
2019年03月30日 12:39:58ncoghlancreate

AltStyle によって変換されたページ (->オリジナル) /