473,378 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

Apr 1 '06 #1
1 1954
As simple and as obvious as I expected, thanks Dennis.

-Alex

Apr 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kamus of Kadizhar | last post by:
Thanks to Robert Brewer, I got enough insight into logging to make it work.... Now I have another issue: file locking. Sorry if this is a very basic question, but I can't find a handy reference...
1
by: Roger | last post by:
I'd like to use a program (roundup) that imports the logging.config module on a machine where I could not get the thread and threading modules to compile. How dangerous is it to changing...
1
by: jjesso | last post by:
I am trying to add a new logging level. logging.config.fileConfig("bengineLog.cfg") logging.CLIENT = logging.INFO + 1 logging.addLevelName( logging.CLIENT, 'CLIENT' ) logging.root.setLevel( )...
0
by: Karuppasamy | last post by:
H I am trying to use the Logging Module provided by Microsoft Application Blocks for .Net I installed everything as per the Instructions given in the 'Development Using the Logging Block' ...
23
by: Rotem | last post by:
Hi, while working on something in my current project I have made several improvements to the logging package in Python, two of them are worth mentioning: 1. addition of a logging record field...
5
by: Dilip | last post by:
I have a tiny design question to ask. I am stuck with a home-brewed logging library that has different methods for logging messages based on severity (like warning, error, information etc.). ...
3
by: Ross Boylan | last post by:
I would like my different threads to log without stepping on each other. Past advice on this list (that I've found) mostly says to send the messages to a Queue. That would work, but bypasses...
2
by: scriptlearner | last post by:
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...
3
by: scriptlearner | last post by:
I am trying to put up a queue (through a logging thread) so that all worker threads can ask it to log messages. However, the problem I am facing is that, well, the logging thread itself is running...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.