Python 2.0

Greg Ewing greg.ewing at compaq.com
Fri Jun 11 02:02:27 CEST 1999


Tim Peters wrote:
> 
> "Therefore, we recommend that the design of finalize methods be kept simple
> and that they be programmed defensively, so that they will work in all
> cases."

In my experience, this advice applies just as much to Python
__del__ methods, their alleged greater predictability
notwithstanding. 

The only times I can recall using __del__
methods were in shadow classes which needed to free resources
in an extension module. I found that I had to program them
very defensively, because when the interpreter shut down,
it would dismantle the contents of my modules in a random
order, causing my __del__ methods to crash if I wasn't
careful.

So I regard the environment of a __del__ method as
pretty much unknowable as well!

Greg




More information about the Python-list mailing list