Advice needed on __del__
Brian Quinlan
brian at sweetapp.com
Tue May 10 08:39:08 EDT 2005
phil wrote:
> I'm probably dense and don't quite get the point, even though I
> have coded about 200,000 lines of Python and coded .5 million lines of
> C before there was a C++
>
> A class instance based language doesn't have to BE C++ to have a
> destructor method.
Very true. But meaningful finalizers are a difficult problem in
languages like Python. For example:
class A:
def __del__(self): print self.b
class B:
def __init__(self, a): self.a = a
def __del__(self): print self.a
a = A()
a.b = B(a)
del a
What should happen? How would you implement that behavior? How would
you implement that behavior on Java and .NET (neither of which
gaurantee that finalizers/destructors will be called).
> All I wanted to know is: is the apparent treatment of __del__
> which SEEMS to work fine for me in 2.3.4 deprecated or mangled
> in some later release or future plans.
__del__ is not currently gauranteed to do anything. Currently it does
something. Depending on that something is a bad idea. Could you explain
your problem in more detail - maybe we'll have some suggestions.
Cheers,
Brian
More information about the Python-list
mailing list