Generator inside a class prevent __del__ ??

Emmanuel eastier at free.fr
Thu Apr 22 05:12:27 EDT 2004



Andrew Bennetts a écrit :

> On Thu, Apr 22, 2004 at 01:26:18AM +0200, Emmanuel wrote:
> >
> >
> > Andrew Bennetts a écrit :
> >
> > > On Wed, Apr 21, 2004 at 02:53:33PM +0200, Emmanuel wrote:
> > > >
> > > > Trouble is, I _would_ like not to care about the lifetime of the object, and I
> > > > don't know where it will be destroyed.
> > >
> > > Then don't use __del__.  Python can and will automatically collect cycles
> > > when the objects *don't* define __del__ methods.
> > >
> > > Out of curiousity, why are you defining __del__ anyway?
> > >
> > > -Andrew.
> >
> > I don't want to use __del__, but I suspected I had an issue with the destruction of
> > my objects, and used a log in __del__ to monitor the destruction.
>
> Except that __del__ affects how they are destructed :)
>
> Weakrefs are probably a better choice for this, as they don't interfere with
> the lifecycle of the object you're interested in, unlike __del__.
>
> > But defining __del__ has also a lot of valuable utilisation, or so I think...
>
> It's only very very rarely useful, in my experience.  Again, weakrefs are
> probably more useful for what you have in mind.
>
> -Andrew.

Ok, I think I don't understand anything anymore...

I thought __del__ was the destructor of the object, like the object::~object in C++ ( my
experience in programming is mainly from C++ ), and so __del__ shouldn't affect when they
are destructed.
And I thought weakref is a way to control the lifetime, ie when the ref count is
decremented, and when to call __del__.

>From what you ( and others ) are saying, I'm proven wrong...

Do you know where I can find more information, beside python doc ?

Thanks,

Emmanuel





More information about the Python-list mailing list