ValueError: I/O operation on closed file

Vinay Sajip vinay_sajip at
Sat Apr 11 02:01:15 CEST 2009

On Apr 10, 9:25 pm, dj <d.a.aberna... at> wrote:
> I have a handler which I use with a set of log levels for the pythonloggingmodule.
> -----------------------------------
> --------------------------------------------------------
> 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\", line 74, in emit
>     if self.shouldRollover(record):
>   File "C:\python26\lib\logging\", line 146, in
> shouldRollover
>, 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.


Vinay Sajip

More information about the Python-list mailing list