Re: [Python-ideas] Automatic context managers

2013-04-26 Thread Chris Angelico
On Sat, Apr 27, 2013 at 1:54 AM, MRAB pyt...@mrabarnett.plus.com wrote: On 26/04/2013 14:02, anatoly techtonik wrote: This circular reference problem is interesting. In object space it probably looks like a stellar detached from the visible (attached) universe. Is the main problem in detecting

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 pyt...@mrabarnett.plus.com wrote: On 26/04/2013 14:02, anatoly techtonik wrote: This circular reference problem is interesting. In

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 pyt...@mrabarnett.plus.com wrote: On 26/04/2013 14:02, anatoly techtonik wrote:

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 da...@davea.name 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

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 da...@davea.name 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

Re: [Python-ideas] Automatic context managers

2013-04-26 Thread 88888 Dihedral
Chris Angelico於 2013年4月27日星期六UTC+8上午12時52分38秒寫道: On Sat, Apr 27, 2013 at 1:54 AM, MRAB pyt...@mrabarnett.plus.com wrote: On 26/04/2013 14:02, anatoly techtonik wrote: This circular reference problem is interesting. In object space it probably looks like a stellar detached from the

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 ros...@gmail.com 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

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 da...@davea.name 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

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: SNIP 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

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 ros...@gmail.com 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

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 Chris Angelico
On Sat, Apr 27, 2013 at 8:50 AM, Ian Kelly ian.g.ke...@gmail.com wrote: On Fri, Apr 26, 2013 at 10:54 AM, Chris Angelico ros...@gmail.com 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

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 da...@davea.name 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 s...@pobox.com wrote: Whenever the GC finds a cycle that is unreferenced but

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 12:12 PM, Skip Montanaro s...@pobox.com 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