[IPython-user] IPython and __del__

Fernando Perez Fernando.Perez at colorado.edu
Tue Nov 29 16:20:27 CST 2005


daishi at egcrc.net wrote:
> Hi,
> 
> I'm encountering some behavior that I don't understand.
> I think it is a bug, but I'd be happy to be enlightened
> otherwise.

Well, it's how python does things:

http://docs.python.org/ref/customization.html

In particular:

"It is not guaranteed that __del__() methods are called for objects that still 
exist when the interpreter exits."

So I'm afraid that this is fully beyond my control.  Who knows what internal 
code path deep in the bowels of the interpeter decides where to stop 
recursively traversing user-defined variables checking for __del__ methods.

Because of the above non-guarantee, the proper 'pythonic' way to do resource 
deallocation is to provide your objects with a close() method which is 
explicitly called.

The fact that you saw this one inside ipython is pure coincidence: the same 
problem can easily appear inside any large program with very large collections 
of objects which need to be released at exit time.

Cheers,

f




More information about the IPython-user mailing list