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

Oliver Schoenborn oliver.schoenborn at utoronto.ca
Thu Jun 10 19:40:49 EDT 2004


Martin,

From: "Martin v. Löwis" <martin at v.loewis.de>
> Oliver Schoenborn wrote:
> > I can accept that only if there is something inherent to the technique
which
> > exploits a non-specified aspect of the language. I can't think of any.
Could
> > you be more specific about what aspect is not portable?
>
> The idea that you can execute code at the end of a function to invoke
> teardown operations, even in the presence of exceptions. That cannot be
> done for Jython, AFAIK. Jython generates Java byte code from Python
> source code, so there is no Python virtual machine anywhere.

That's assuming that what you say below is true. The technique, shown in
scope.py attached to the first post to python-dev, is simple (and consists
in rebinding a function to a wrapper that puts a try/finally around the
original function, with some special behind-the-scenes stuff for what to
execute in the finally block). Scope.py works here, so I don't understand
your statement that the technique doesn't work in Python.

> > If it is portable, then since it works as-is in Python, it could be put
into
> > the specs.
>
> It doesn't work in Python. I believe your implementation also fails in
> Jython (but didn't test).

Unless we're talking cross-purpose here, scope.py shows it works at least in
Python downloaded from python.org. Again, could you please be more specific,
pointing to which part of the code is allegedly flawed or not portable?

Oliver




More information about the Python-Dev mailing list