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

"Martin v. Löwis" martin at v.loewis.de
Sat Jun 12 08:36:48 EDT 2004


David Abrahams wrote:
> I'm sure I missed something important along the way here, but the fact
> that you can generate Java bytecode for Python's "finally" in Jython,
> it seems to me, _proves_ that you can also generate code to that will
> be executed at the end of a function even in the presence of
> exceptions.

Certainly. However, I'm uncertain whether you find out, in this finally
block, what objects require this finally-ization. Part of this 
uncertainty comes from my failure to understand how the proposed
mechanism works in the first place - ie. what is the precise set of
objects that should be finally-ized. If any algorithm for such a
mechanism would need to find out what objects have been created while
the function was running, and invoke finally-ization on those, that
may not be possible to implement: you can't get hold of all objects
that have been created in Java, AFAIK (1). If it involves looking at
all local variables, it might be implementable, but might cause a
significant slowdown even if the feature is not used.

Regards,
Martin

(1) that is currently not possible in Python, either, but
it might be possible to change the interpreter to record the list
of young objects in the thread state.




More information about the Python-Dev mailing list