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

"Martin v. Löwis" martin at v.loewis.de
Thu Jun 10 01:22:57 EDT 2004

Oliver Schoenborn wrote:
> This is a module I made to test a concept of finalization *not* based on
> __del__. I'm curious to find out if the techniques look like they could be
> implemented directly in the Python interpreter to lessen the burden on the
> user, which is why I post this here.

Yes, it could be implemented directly on the user. However, I notice
that the algorithm you implement has nothing to do with finalization.

Typically, the term finalization is associated with objects whose
life is about to end, i.e. objects which should cease to exist.

Python does provide finalization, and in a reliable way: the finalizer
is called before the object goes away, guaranteed.

What you want is a function that is called when the object goes of of
some scope. This is something completely different, as the object may
life long and prosper even after it goes out of scope. You have an

     assert sys.getrefcount(self) == 5

It is very easy to trigger that assertion, so I'm uncertain what
the intended meaning of that assertion is.

In summary: to avoid confusion, you should not use the term
"finalization" when talking about the mechanisms you have implemented
in the module.


More information about the Python-Dev mailing list