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 this:
Traceback (most recent call last):
File "C:\Python24\lib\logging\__init__.py", line 712, in emit
self.stream.write(fs % msg)
ValueError: I/O operation on closed file
So is there no way to use the logger object in a __del__
I wanted to use the message to clearly indicate in the logger file that
the instance had closed ok.
Regards,
Benedict 2 3296
flupke <flupke <at> nonexistingdomain.com> writes: 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 this: Traceback (most recent call last): File "C:\Python24\lib\logging\__init__.py", line 712, in emit self.stream.write(fs % msg) ValueError: I/O operation on closed file
So is there no way to use the logger object in a __del__ I wanted to use the message to clearly indicate in the logger file that the instance had closed ok.
It all depends. If your __del__ is being called via atexit() for application
cleanup, for example, logging may not be available to you because it has been
cleaned up beforehand.
The logging module registers an atexit() handler to flush and close handlers
before script termination.
Vinay Sajip
Vinay Sajip wrote: flupke <flupke <at> nonexistingdomain.com> writes:
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 this: Traceback (most recent call last): File "C:\Python24\lib\logging\__init__.py", line 712, in emit self.stream.write(fs % msg) ValueError: I/O operation on closed file
So is there no way to use the logger object in a __del__ I wanted to use the message to clearly indicate in the logger file that the instance had closed ok.
It all depends. If your __del__ is being called via atexit() for application cleanup, for example, logging may not be available to you because it has been cleaned up beforehand.
The logging module registers an atexit() handler to flush and close handlers before script termination.
Vinay Sajip
Thanks i was able to solve it using a function registered in both the
classes i used in that project.
Why would one use __del__ instead of atexit then especially if the calls
you make in __del__ are so unrelieable?
Regards,
Benedict This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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:
|
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...
|
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.
...
|
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...
|
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...
|
by: Robert Rawlins |
last post by:
Hi Fredrik,
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...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |