Calling A Deconstructor
John Abel
john.abel at pa.press.net
Fri Nov 15 10:01:46 EST 2002
Thanks very much that. Explains a lot. A lot of the docs I've read,
mention the __init__, but not much on the __del__.
Thanks again.
John
sismex01 at hebmex.com wrote:
>>From: John Abel [mailto:john.abel at pa.press.net]
>>Sent: Friday, November 15, 2002 7:47 AM
>>
>>Hi,
>>
>>I have a class, with an __init__, and a main function, basically a
>>wrapper around smtplib. I wish to add a __del__ to the class. Two
>>questions: Do I need to do it this way? If so, how do I can
>>close the instance, so the __del__ is called? The script will be
>>permanently resident, so I wanted to make sure that I didn't have
>>various connections open to the smtp server.
>>
>>Thanks
>>
>>John
>>
>>
>>
>
>Hmm... interesting conundrum.
>
>An object is "deleted" automatically when the last reference
>to it disappears (goes out of scope, is deleted explícitly,
>etc). BUT, you can't force the __del__ method to be called,
>it's an implementation detail that depends on the memory
>management scaffolding in place.
>
>For example. In CPython, memory management is done via
>reference counting; when the refcount of an object drops
>to zero, it's immediately destructed and deallocated; BUT,
>in Jython, memory management is done via Java's machinery,
>and there is no assurement of *when*, or *if*, the
>destructor is going to be called on the object.
>
>So, for sanity's sake, use a .close() method, or a .done(),
>or something like that, to explicitly close your connection
>to your SMTP server, so you won't have to depend on __del__
>doing it for you.
>
>Python doesn't have the fixed semantics for destructor
>invocation that C++ has, so you have to take that into account
>when designing your software.
>
>HTH
>
>-gustavo
>
>pd: TGIF!
>
>
--
*John Abel
Systems Administrator *
PA News Limited
www.pa.press.net <http://www.pa.press.net>
E-Mail address: john.abel at pa.press.net <mailto:john.abel at pa.press.net>
Telephone Number : 01430 455553
Fax Number : 0870 1240192
Mobile Number : 07971 611356
The Bishop's Manor, Market Place, Howden, DN14 7BL
PA News Limited, 292 Vauxhall Bridge Road, London SW1V 1AE. Registered
in England No. 3891053.
More information about the Python-list
mailing list