Re: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)

2013-04-26 Thread Chris Angelico
On Sat, Apr 27, 2013 at 12:12 PM, Skip Montanaro wrote: > From the Zen of Python: > >> In the face of ambiguity, refuse the temptation to guess. > > I believe the reason something isn't already done to break cycles is > that the authors of the cyclic garbage collector considered the above > aphori

Re: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)

2013-04-26 Thread Skip Montanaro
>From the Zen of Python: > In the face of ambiguity, refuse the temptation to guess. I believe the reason something isn't already done to break cycles is that the authors of the cyclic garbage collector considered the above aphorism. They rely on the author of the code with the cycles to figure

Re: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)

2013-04-26 Thread Chris Angelico
On Sat, Apr 27, 2013 at 9:45 AM, Dave Angel wrote: > I didn't know there was a callback that a user could hook into. That's very > interesting. > On Sat, Apr 27, 2013 at 10:22 AM, Skip Montanaro wrote: >> Whenever the GC finds a cycle that is unreferenced but uncollectable, >> it stores those o

Re: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)

2013-04-26 Thread Chris Angelico
On Sat, Apr 27, 2013 at 8:50 AM, Ian Kelly wrote: > On Fri, Apr 26, 2013 at 10:54 AM, Chris Angelico wrote: >> Once it's been proven that there's an unreferenced cycle, why not >> simply dispose of one of the objects, and replace all references to it >> (probably only one - preferably pick an obj

Re: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)

2013-04-26 Thread Skip Montanaro
> Whenever the GC finds a cycle that is unreferenced but uncollectable, > it stores those objects in the list gc.garbage. At that point, if the > user wishes to clean up those cycles, it is up to them to delve into > gc.garbage, untangle the objects contained within, break the cycles, > and remove

Re: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)

2013-04-26 Thread Dave Angel
On 04/26/2013 06:50 PM, Ian Kelly wrote: On Fri, Apr 26, 2013 at 10:54 AM, Chris Angelico wrote: Once it's been proven that there's an unreferenced cycle, why not simply dispose of one of the objects, and replace all references to it (probably only one - preferably pick an object with the fewes

Re: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)

2013-04-26 Thread Dave Angel
On 04/26/2013 06:43 PM, Ian Kelly wrote: Whenever the GC finds a cycle that is unreferenced but uncollectable, it stores those objects in the list gc.garbage. At that point, if the user wishes to clean up those cycles, it is up to them to delve into gc.garbage, untangle the objects contai

Re: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)

2013-04-26 Thread Ian Kelly
On Fri, Apr 26, 2013 at 1:31 PM, Dave Angel wrote: > On 04/26/2013 01:57 PM, Chris Angelico wrote: >> And yeah. If you catch the exception inside __del__, you can cope with >> the destructed object yourself (or LBLY, if you wish). Alternatively, >> you just proceed as normal, and when your __del__

Re: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)

2013-04-26 Thread Ian Kelly
On Fri, Apr 26, 2013 at 10:54 AM, Chris Angelico wrote: > Once it's been proven that there's an unreferenced cycle, why not > simply dispose of one of the objects, and replace all references to it > (probably only one - preferably pick an object with the fewest > references) with a special tempora

Re: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)

2013-04-26 Thread Dave Angel
On 04/26/2013 01:57 PM, Chris Angelico wrote: On Sat, Apr 27, 2013 at 3:42 AM, Dave Angel wrote: I don't see what your "special" temporary object actually accomplishes. Seems to me you need to declare that your __del__() methods promise not to reference each other, and the gc would then check a

Re: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)

2013-04-26 Thread Chris Angelico
On Sat, Apr 27, 2013 at 3:42 AM, Dave Angel wrote: > I don't see what your "special" temporary object actually accomplishes. > Seems to me you need to declare that your __del__() methods promise not to > reference each other, and the gc would then check all objects in the cycle, > and do its prese

Re: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)

2013-04-26 Thread Dave Angel
On 04/26/2013 12:54 PM, Chris Angelico wrote: [[ Resending under a more appropriate subject line... sorry about that, ignore the other one as it'll only confuse matters ]] On Sat, Apr 27, 2013 at 1:54 AM, MRAB wrote: On 26/04/2013 14:02, anatoly techtonik wrote: This circular reference proble

CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)

2013-04-26 Thread Chris Angelico
[[ Resending under a more appropriate subject line... sorry about that, ignore the other one as it'll only confuse matters ]] On Sat, Apr 27, 2013 at 1:54 AM, MRAB wrote: > On 26/04/2013 14:02, anatoly techtonik wrote: >> This circular reference problem is interesting. In object space it >> proba