473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

RE: Logging in __del__()

Hi Fredrik,
When the application is running, or when it is shutting down?
This is interesting, I did a test where I explicitly destroyed the instance
using 'del my_instance' while the application was running and no error was
thrown.

It would see you are right, when the application ends it kills the logging
module before my classes. I think you're on the right approach just
try/except it and leave it be.

Am I right in thinking that Python destroys instances of classes when it
deems they are no longer needed? I shouldn't have to explicitly delete the
classes, right?

Thanks Fredrik,

Robert

Jul 15 '08 #1
3 1456
On Jul 15, 1:51 pm, "Robert Rawlins"
<robert.rawl...@thinkbluemedia.co.ukwrote:
>
Am I right in thinking that Python destroys instances of classes when it
deems they are no longer needed? I shouldn't have to explicitly delete the
classes, right?
Python uses reference counting with a cycle detector, but the
detector's behaviour is different if there are finalizers (__del__) -
see

http://www.python.org/doc/ext/refcounts.html

Regards,

Vinay Sajip
Jul 15 '08 #2
Hi Vinay,
Python uses reference counting with a cycle detector, but the
detector's behaviour is different if there are finalizers (__del__) -
see

http://www.python.org/doc/ext/refcounts.html
Thank you for the link, that certainly explains a great deal.

So, am I right to assume that python will still handle its garbage disposal
if I implement __del__(), it just handles circular references in a slightly
different way, but to the same effect. Right?

Cheers,

Robert

Jul 16 '08 #3
On Wed, 16 Jul 2008 12:38:50 +0100, Robert Rawlins wrote:
So, am I right to assume that python will still handle its garbage disposal
if I implement __del__(), it just handles circular references in a slightly
different way, but to the same effect. Right?
No. Circular references in objects with a `__del__()` implementation are
not collected! Why are you using `__del__()` anyway? Are you aware of
the promises that are *not* made! It's not guaranteed when the method
is called nor if it is called at all!

Ciao,
Marc 'BlackJack' Rintsch
Jul 16 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: seth | last post by:
Last week I encountered an AttributeError in my unit tests that I wasn'table to catch with an "except AttributeError" statement. The problem stemmed from a class that raised an error inside...
2
by: Kepes Krisztian | last post by:
Hi ! I very wonder, when I get exp. in java with GC. I'm Delphi programmer, so I get used to destructorin objects. In Java the final method is not same, but is like to destructor (I has...
6
by: Peter Abel | last post by:
I have an application, which is an instance of a class with a deeply nested object hierarchy. Among others one method will be executed as a thread, which can be stopped. Everything works fine...
13
by: Emmanuel | last post by:
Hi, I run across this problem, and couldn't find any solution (python 2.2.2) : Code : =========== from __future__ import generators >>> class titi:
1
by: schwerdy | last post by:
Hello developers! I'm using Python 2.3.4 under debian Sarge and want to write a small logger class. My source code reads: #*************************************************** import sys, time...
2
by: flupke | last post by:
Hi, i have a class and a class attribute log which is a logger object. In the __del__() function i want to log a message but it fails even if i use self.__class__.log. The error i get is...
1
by: Erwan Adam | last post by:
Hello all, Can someone reproduce this bug ... I use : python Python 2.4.3 (#2, Sep 18 2006, 21:07:35) on linux2 Type "help", "copyright", "credits" or "license" for more information. ...
6
by: George Sakkis | last post by:
I'm baffled with a situation that involves: 1) an instance of some class that defines __del__, 2) a thread which is created, started and referenced by that instance, and 3) a weakref proxy to the...
0
by: Fredrik Lundh | last post by:
Robert Rawlins wrote: When the application is running, or when it is shutting down? Python makes no guarantees that it will tear down your objects before it tears down the library's...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.