Logging in __del__()

Fredrik Lundh fredrik at pythonware.com
Tue Jul 15 13:42:37 CEST 2008


Robert Rawlins wrote:

> I then get the following exception thrown when running my code:

When the application is running, or when it is shutting down?

> Traceback (most recent call last):
>   File "/usr/lib/python2.5/logging/handlers.py", line 73, in emit
>     if self.shouldRollover(record):
>   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?

Python makes no guarantees that it will tear down your objects before it 
tears down the library's objects (or the library itself).  See e.g.

     http://www.python.org/doc/essays/cleanup/

(old and probably somewhat outdated, but you get the idea)

I'd just put a try/except around it, and ignore any exceptions that may 
occur.

</F>




More information about the Python-list mailing list