[Zope] __del__ not being called.

Malcolm Tredinnick malcolm@commsecure.com.au
Fri, 21 Apr 2000 09:23:27 +1000


On Thu, Apr 20, 2000 at 09:24:46AM -0400, John Sutherland wrote:
> > On Wed, Apr 19, 2000 at 07:53:09PM -0400, 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"
> > In python, the __del__ method doesn't get called until every
> > reference to the
> > object has disappeared and it is being garbage collected. The "del foo"
> > statement jsut decreases the reference count of foo by 1 (and when it hits
> > zero, it is garbage collected).
> 
> Doah... I guess it plainly obvious I'm not a python person eh? Just learning
> it.. But I definitly like it..
> 
> How to I know when an instance is deleted?? I need this to be able to remove
> a record in a DB.. Any suggestions?

In general, this is difficult. When I've implemented things like persistent
classes in Python (objects that have to save themselves when they go out of
scope), I've either been in a situation where only one instance of the object
can exist at any given time (implemented via file locking usually), or called
a close() method when I knew the instance was about to be deleted.

If you want to give me more details of your specific case (via private email
maybe and then we can post a summary of the conclusions to the list), I might
be able to offer more specific help.

Cheers,
Malcolm

-- 
Malcolm Tredinnick               ph: +61 2 9440 9885
CommSecure Pty Ltd           mobile: 0409 663 876
                              email: malcolm@commsecure.com.au