Message89091
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() |
|
Date |
User |
Action |
Args |
2009-06-08 16:34:16 | rcronk | set | recipients:
+ rcronk, vinay.sajip, mramahi77, lowell87, neyro, Frans |
2009-06-08 16:34:16 | rcronk | set | messageid: <1244478856.59.0.345131207011.issue4749@psf.upfronthosting.co.za> |
2009-06-08 16:34:15 | rcronk | link | issue4749 messages |
2009-06-08 16:34:14 | rcronk | create | |
|