Robert Cronk <cron...@gmail.com> added the comment:

I have a small script that reproduces the problem.  I couldn't 
reproduce it until I added some os.system() calls in the threads that 
were logging.  Here's the output using python 2.6.1:


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


Here is the script - let me know if I'm doing things incorrectly:

import os, threading, logging, logging.handlers

class LoggerThread(threading.Thread):
    def __init__(self, numLoops):
        threading.Thread.__init__(self)
        self.numLoops = numLoops


    def run(self):
        for x in range(0, self.numLoops):
            os.system('cd.>blah.txt')
            os.system('del blah.txt')
            logging.debug('This is log message ' + str(x) + ' from ' + 
self.name + ' and I think this should be a little longer, so I\'ll add 
some more data here because perhaps the size of the individual log 
message is a factor.  Who knows for sure until this simple test fails.')


if __name__=="__main__":
    logSize = 2048
    numberOfLogs = 10

    files = logging.handlers.RotatingFileHandler('logthred.log', 'a', 
logSize, numberOfLogs)
    console = logging.StreamHandler()

    # set a format
    fileFormatter = logging.Formatter('%(asctime)s %(levelname)-8s %
(thread)-4s %(message)s')
    consoleFormatter = logging.Formatter('%(asctime)s %(levelname)-8s %
(thread)-4s %(message)s')

    # tell the handler to use this format
    files.setFormatter(fileFormatter)
    console.setFormatter(consoleFormatter)

    # add the handlers to the root logger
    logging.getLogger('').addHandler(files)
    logging.getLogger('').addHandler(console)
    logging.getLogger('').setLevel(logging.DEBUG)

    numThreads = 10
    numLoops = 100

    # Create and execute threads
    for x in range(0, numThreads):
        LoggerThread(numLoops).start()

----------
Added file: http://bugs.python.org/file14226/logthred.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue4749>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to