[Python-Dev] Re: Object finalization for local (ie function) scopes

Aahz aahz at pythoncraft.com
Tue Jun 15 18:23:03 EDT 2004


On Tue, Jun 15, 2004, Guido van Rossum wrote:
>Oliver:
>>
>> My only problem with PEP 310 is that the solution it proposes doesn't
>> address the problem that the user of a class still needs to be the one to
>> take care of ordering cleanup. So I would have prefered something that the
>> coder of a class uses to tell the interpreter "any instance of this object
>> needs deterministic cleanup", so the user can just be carefree when using
>> that class.
> 
> This is a fallacy, because the user still has to order the cleanup by
> using the correct decorator.  We can't afford to decorate *every*
> function with this mechanism (method calls are already too expensive).

My impression is that if integrated into the interpreter core, this
wouldn't be particularly expensive.  Fundamentally, it would look
something like this:

    class C(RAII):
        def __init__(self):
            RAII.register(self)

    def foo():
        x = C()

then somewhere in the guts of the function calling mechanism, just
before the scope unwinding, we'd have:

    for o in registered_objects:
        o.__finalize__()

This is IMO an attractive nuisance, but I don't think it imposes much
burden in execution speed.  I do see the attraction as being similar to
that of metaclasses and decorators: power provided to the end-developer
with few demands for understanding.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha



More information about the Python-Dev mailing list