[Python-3000] PEP: Eliminate __del__

Giovanni Bajo rasky at develer.com
Tue May 1 13:32:52 CEST 2007

On 01/05/2007 9.31, Raymond Hettinger wrote:

> PEP:  Eliminating __del__

*sigh* I'm still -1, but I won't revive the discussion of course.

I would still like if the PEP listed the alternative me and others were 
proposing, that is changing the semantic of __del__ (or dropping __del__ in 
favor of a new __close__ method with the new semantic) such as:

  1) It is guaranteed to be called only once per object.
  2) In case of circular reference, __del__ methods are called in random order 
on the objects of the cycle, and then the cycle is broken. (This is because 
step #1 fixes the main problem with calling __del__ in random orders).

In fact, your PEP concentrates on the problem of implicit finalization, which 
I don't think it's generally perceived as *the* problem with __del__. I'm 
still a *strong* proponent of implicit finalization (aka RAII). It always 
worked well for me.

The problem is that __del__ currently *breaks* implicit finalization, causing 
garbage if it's used by objects in a cycle. With the fixes above, I'd use it 
more not less.
Giovanni Bajo

More information about the Python-3000 mailing list