__del__ and logging
flupke
flupke at nonexistingdomain.com
Mon May 2 05:54:38 EDT 2005
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
More information about the Python-list
mailing list