OS: Solaris 9
Python Version: 2.4.4
I need to log certain data in a worker thread; however, I am getting
an error now when I use two worker threads.
I think the problem comes from the line
logging.info('T hread Object (%d):(%d), Time:%s in seconds %d'%
(self.no,self.d uration,time.ct ime(),time.time ()))
when multiple worker thread is trying to update the log files.
What did I do wrong? Should I lock the log file before writing to
it? Thanks.
Traceback (most recent call last):
File "/tools/python-2_4_4.i386.sola ris.5_9/lib/python2.4/logging/
__init__.py", line 737, in emit
self.stream.wri te(fs % msg)
ValueError: I/O operation on closed file
Traceback (most recent call last):
File "/tools/python-2_4_4.i386.sola ris.5_9/lib/python2.4/logging/
__init__.py", line 737, in emit
self.stream.wri te(fs % msg)
ValueError: I/O operation on closed file
class Worker(threadin g.Thread):
def __init__(self,n o,duration):
threading.Threa d.__init__(self )
self.no = no
self.duration = duration
def run(self):
end = time.time() + self.duration
while(end time.time()):
logging.info('T hread Object (%d):(%d), Time:%s in seconds
%d'%(self.no,se lf.duration,tim e.ctime(),time. time()))
time.sleep(10)
def main():
children = []
logging.basicCo nfig(level=logg ing.INFO,
format='%(ascti me)s %(levelname)s %
(message)s',
filename='logs/myapp.log',
filemode='w')
args = parseArgs()
for i in range(args.thre ads):
logging.info('i =%d'%(i))
children.append (Worker(i,args. duration))
children[i].start()
time.sleep(0.1)
Python Version: 2.4.4
I need to log certain data in a worker thread; however, I am getting
an error now when I use two worker threads.
I think the problem comes from the line
logging.info('T hread Object (%d):(%d), Time:%s in seconds %d'%
(self.no,self.d uration,time.ct ime(),time.time ()))
when multiple worker thread is trying to update the log files.
What did I do wrong? Should I lock the log file before writing to
it? Thanks.
Traceback (most recent call last):
File "/tools/python-2_4_4.i386.sola ris.5_9/lib/python2.4/logging/
__init__.py", line 737, in emit
self.stream.wri te(fs % msg)
ValueError: I/O operation on closed file
Traceback (most recent call last):
File "/tools/python-2_4_4.i386.sola ris.5_9/lib/python2.4/logging/
__init__.py", line 737, in emit
self.stream.wri te(fs % msg)
ValueError: I/O operation on closed file
class Worker(threadin g.Thread):
def __init__(self,n o,duration):
threading.Threa d.__init__(self )
self.no = no
self.duration = duration
def run(self):
end = time.time() + self.duration
while(end time.time()):
logging.info('T hread Object (%d):(%d), Time:%s in seconds
%d'%(self.no,se lf.duration,tim e.ctime(),time. time()))
time.sleep(10)
def main():
children = []
logging.basicCo nfig(level=logg ing.INFO,
format='%(ascti me)s %(levelname)s %
(message)s',
filename='logs/myapp.log',
filemode='w')
args = parseArgs()
for i in range(args.thre ads):
logging.info('i =%d'%(i))
children.append (Worker(i,args. duration))
children[i].start()
time.sleep(0.1)
Comment