[Python-ideas] Automatic context managers

anatoly techtonik techtonik at gmail.com
Fri Apr 26 19:31:06 CEST 2013


On Fri, Apr 26, 2013 at 6:54 PM, MRAB <python at mrabarnett.plus.com> wrote:

> On 26/04/2013 14:02, anatoly techtonik wrote:
>
>> On Thu, Apr 25, 2013 at 9:17 AM, Steven D'Aprano <steve at pearwood.info
>> <mailto:steve at pearwood.info>> wrote:
>>
> [snip]
>
>  I am not touching destructor methods. The idea is to make with statement
>> transparent - embed inside objects that require it. I am not sure what
>> the implementation should be. Probably object should have an ability to
>> enable context scope tracking in its constructor, to tell Python to call
>> its __exit__ method at the moment when its reference count reaches zero,
>> and before it is garbage collected.
>>
>>     On the other hand, objects being freed is not deterministic. They'll
>>     be freed when there are no longer any references to it, which may be
>>     Never.
>>
>>     Reference counting GCs are deterministic, but cannot deal with
>>     circular references. Other GCs can deal with circular references,
>>     but are non-deterministic. Even the Java GC doesn't guarantee that
>>     the finalize() method will always be called.
>>
>>
>> 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 it?
>>
>>  The problem is in knowing in which order the objects should be
> collected.
>
> For example, if A refers to B and B refers to A, should you collect A
> then B, or B then A? If you collect A first, then, for a time, B will
> be referring to a non-existent object. That's not good if the objects
> have destructors which need to be run.


And how does GC solve that? Can it complain about those stellars?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130426/21b37fb3/attachment.html>


More information about the Python-ideas mailing list