ValueError: I/O operation on closed file

Vinay Sajip vinay_sajip at yahoo.co.uk
Sat Apr 11 02:01:15 CEST 2009


On Apr 10, 9:25 pm, dj <d.a.aberna... at gmail.com> wrote:
> I have a handler which I use with a set of log levels for the pythonloggingmodule.
>
> ----------------------------------- myhandler.py
> --------------------------------------------------------
> importlogging.handlers
>
> # create my handler class
> class MyHandler(logging.handlers.RotatingFileHandler):
>     def __init__(self, fn):
>        logging.handlers.RotatingFileHandler.__init__(self, fn,
>
> maxBytes=10485760, backupCount=5)
>
> # Register handler in the "logging.handlers" namespacelogging.handlers.MyHandler = MyHandler
> --------------------------------------------------------------------------------------------------------------------
>
> Using it, repeatedly generates this error:
>
> Traceback (most recent call last):
>   File "C:\python26\lib\logging\handlers.py", line 74, in emit
>     if self.shouldRollover(record):
>   File "C:\python26\lib\logging\handlers.py", line 146, in
> shouldRollover
>     self.stream.seek(0, 2)  #due to non-posix-compliant Windows
> feature
> ValueError: I/O operation on closed file
>
> I am completely stumped  has to what could be the issue.
> Any help would be greatly appreciated.

Not sure - you may need to post a small script which demonstrates the
error repeatably. Otherwise, it may be caused by e.g. other handles
being open to the same file (say, if you open a FileHandler and a
RotatingFileHandler with the same path, or have one of the log files
open in an editor which locks the file.

Regards,

Vinay Sajip



More information about the Python-list mailing list