Generator inside a class prevent __del__ ??
andrew-pythonlist at puzzling.org
Thu Apr 22 02:27:22 CEST 2004
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.
More information about the Python-list