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

Oliver Schoenborn oliver.schoenborn at utoronto.ca
Mon Jun 14 12:03:41 EDT 2004

From: "Moore, Paul" <Paul.Moore at atosorigin.com>
> From: Oliver Schoenborn
> > surprised there hasn't been more given how fundamental the problem
> > of RAII is in Python.
> It's not at all clear that there *is* a "problem of RAII" in Python.
> Regardless, you may want to look at PEP 310, and the (extensive)
> threads on python-dev which it spawned, for an alternative view of
> the issue.

Already have. As mentioned in a discussion off list, I quite like 310.
However, I also troweled the python-dev archives and didn't seen any
discussion of anything related to the try/finally wrapping that I mentioned,
and since the implementation could likely be cleaner and more performant if
implemented in the interpreter directly, and would not require change to the
language itself, I mentioned it here. But that's the only reason for coming
to python-dev.

> To summarise, I think you
> should consider whether PEP 310 is what you need

310 is a good, fairly clean compromise.

> (it's probably mode
> Pythonic than overloading __del__ the way C++ does)

I agree, that's certainly *not* what I would advocate. But since you bring
it up, is there any reason why a new method like, say, __deterministic__,
couldn't be added, and any class that has it means that interpreter calls
that method upon scope exit if exception has been thrown *or* object


More information about the Python-Dev mailing list