[Zope] __del__ not being called.

Michel Pelletier michel@digicool.com
Mon, 24 Apr 2000 14:22:26 -0700


Garion wrote:
> 
> For some reason, in my product, the __del__(self) is not being called
> when I delete an instance of it.. I currently have it defined as:
> 
>     def __del__(self):
>         raise "DEBUG", "TEST"
> 
> Just to see what is going on... Any ideas?

First, exceptions raised in __del__ are ignored.  See the Python
Language Reference, section 3.3.1:

http://www.python.org/doc/current/ref/customization.html#l2h-127

Second, __del__ is not called when your object is 'deleted' from the
managment interface.  __del__ is called when the instance is destroyed
in memory.  In the usual case this is when the instance's ref-count
drops to zero.  In the case of Zope objects that are in memory
('activated') when the ref-count of an instance drops to one, then the
only object that references the instance is the object cache itself; in
this case the cache deletes its reference to the instance (dropping the
ref-count to zero) and the object's __del__ method is called.

This is way low-level stuff.  What you are looking for is
manage_beforeDelete.  Check out:

http://www.zope.org/Members/michel/Projects/Interfaces/ObjectManagerItem

and scroll down to the 'Hooks' section.

-Michel