Logging in __del__()
robert.rawlins at thinkbluemedia.co.uk
Tue Jul 15 13:32:06 CEST 2008
I'm trying to help trace when instances of particular classes are being
destroyed by the garbage collector and thought the cleanest way would be to
implement a logging call in __del__() on the class. However, I'm having an
I inject a logger instance into my class upon construction and set it to
self.logger, I then use this within the class to log actions going on
within, works fine.
Now, when I make the call in the __del__() method like so:
# Log the classes destruction.
self.logger.debug("Class Instance Destroyed")
I then get the following exception thrown when running my code:
Traceback (most recent call last):
File "/usr/lib/python2.5/logging/handlers.py", line 73, in emit
File "/usr/lib/python2.5/logging/handlers.py", line 147, in shouldRollover
self.stream.seek(0, 2) #due to non-posix-compliant Windows feature
ValueError: I/O operation on closed file
Does anyone have any ideas as to what I'm doing wrong here? Is this a known
issue which has a neat little work around?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list