does python have useless destructors?

Donn Cave donn at u.washington.edu
Fri Jun 18 18:35:49 CEST 2004


In article <m34qp9ma5h.fsf at pc150.maths.bris.ac.uk>,
 Michael Hudson <mwh at python.net> wrote:

> Donn Cave <donn at u.washington.edu> writes:
> 
> > In article <m3hdtam7z0.fsf at pc150.maths.bris.ac.uk>,
> >  Michael Hudson <mwh at python.net> wrote:
> > 
> > > Donn Cave <donn at u.washington.edu> writes:
> > > 
> > > > In article <m3k6y6o8cd.fsf at pc150.maths.bris.ac.uk>,
> > > >  Michael Hudson <mwh at python.net> wrote:
> > > > > Donn Cave <donn at u.washington.edu> writes:
> > > > > > In article <m3fz8xozi1.fsf at pc150.maths.bris.ac.uk>,
> > > > > >  Michael Hudson <mwh at python.net> wrote:
> > > > > > > I would urge everyone participating in this thread to read PEP 
> > > > > > > 310,
> > > > > > > the email conversation linked therein and (optional) *understand* 
> > > > > > > it.
> > > > > > 
> > > > > > It seems to be superficially similar to finalization, 
> > > > > 
> > > > > OK, I've found this thread pretty hard to follow.  What is
> > > > > "finalization" in context?
> > > > 
> > > > Operational definition would be `call __del__ or its C equivalent',
> > > > at the effective end of the object's lifetime.
> > > 
> > > OK.  I claim you can't really have that, and that you don't really
> > > need it anyway.  The idea behind PEP 310 is to acheive the ends of
> > > RAII in C++ by different means.
> > > 
> > > What else do you want to use __del__ methods for?
> > 
> > That would be my question.  That's what __del__ methods _are_
> > used for.  C Python users _do_ really have that, it just takes
> > more care than we like if it needs to be 100% reliable.
> 
> Now you've lost me.
> 
> What did the last __del__ method you wrote do?

I can't specifically remember the last one, but scrounging
around a bit I see an application where I have a __del__
method that releases a kernel semaphore, and a dealloc function
that quits its kernel thread and adds a pending call to delete
its Python thread state.

I wonder if I have created confusion by not getting the
antecedents right, or something like that, when responding
to your question.  All I'm saying is that we do have finalization
in C Python, and that's what __del__ is about as far as I can
tell.  I don't know what RAII means (or doesn't mean) well
enough to make any difference (now I know what the acronym is,
but what do automatic variables have to do with Python?)

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list