Logging and threading



I'm having some problems getting the logging module to work with the
threading module. I've narrowed the problem down to the following
code:

import logging, threading

update_log = logging.getLogger('update_log')
update_log.addHandler(logging.FileHandler("/tmp/update_log"))

class dlThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)

def run(self):
ul = logging.getLogger('update_log')
ul.warn("log this")
print "finished"

t = dlThread()
t.start()

When executed, I receive the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python2.4/logging/__init__.py", line 735, in
emit
self.stream.write(fs % msg)
ValueError: I/O operation on closed file

The exception isn't fatal though, as the print "finished" line is
executed. Alternately, if I run dlThread.run directly everything works
as I would expect, albeit without the multithreading. Since the
logging module is advertised as being threadsafe, I suspect there's
something basic I don't understand about threads.

-Alex

.



Relevant Pages

  • logging and PyQt4
    ... I have a multi-threaded PyQt4 application which has both a GUI and command- ... it is more efficient than the native python threading module. ... Is it wise to use python's logging module in conjunction with Qt4 threads? ...
    (comp.lang.python)
  • ReaderWriterLock with low timeout throws unhandled exception
    ... I am working on improving my threading skills and came across a question. ... When working with the ReaderWriterLock class, ... The logic answer I can think of is, that if one specifies a timeout, then ... the CLR respects that and throws an exception regardless of what's inside ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Starting a thread before wxPython bootup ... interesting.
    ... I'm having an issue with mixing wxPython and threading ... ... That's quite a broad and poorly specified problem to ask people to ... exception without saying what it was. ...
    (comp.lang.python)
  • Re: Web Services Client Error
    ... to be unable to catch a .NET exception. ... The only complication which has just come to mind is threading - am I ... correct in assuming that by wrapping the whole program in a block like ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: DTS from C#
    ... From a console application, WinForms, ASP.NET? ... > What threading option are you using? ... whatever the default in C# code is - as an ex-VB head ... Yes I am catching the COM exception explicity. ...
    (microsoft.public.sqlserver.dts)