473,382 Members | 1,710 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,382 software developers and data experts.

Logging hangs thread after detaching a StreamHandler's terminal

Hi all,

After many hours, I think I've found a bug in the logging module!

If you add a (stdout) StreamHandler to a logger, then detach the
terminal for that stdout, subsequent calls to log() will hang the
calling thread.

To reproduce this, write the following scripts (this was a small test
case I came up with - maybe there's something simpler):

$ cat tryhup.bash
#!/usr/bin/env bash
scp hup.* localhost:
ssh localhost './hup.bash ; while true ; do sleep 1 ; done'

$ cat hup.bash
#!/usr/bin/env bash
../hup.py &

$ cat hup.py
#!/usr/bin/env python
import time
import logging
f = file( '/tmp/hup.out', 'w' )
try:
logging.basicConfig( filename = '/tmp/lup.out', filemode = 'w' )
# XXX PROBLEM LINE BELOW
logging.getLogger('').addHandler( logging.StreamHandler() )
while True:
f.write( '-------\n' )
f.flush()
logging.critical( '======' )
time.sleep(1)
finally:
f.close()

Run ./tryhup.bash. It will sit in an idle spin. Monitor the files
/tmp/hup.out and /tmp/lup.out. Hit Ctrl-C on tryhup to kill it. The
python process is still running, but is stalled (the .out files are no
longer changing).

If you remove the above labeled line, however, this doesn't happen.

Can anybody please acknowledge this bug? Any temporary workarounds to
this problem? Thanks in advance for looking into this and for hearing
me in!

Feb 14 '06 #1
1 2232

py*******************@spamgourmet.com wrote:
Hi all,

After many hours, I think I've found a bug in the logging module!

If you add a (stdout) StreamHandler to a logger, then detach the
terminal for that stdout, subsequent calls to log() will hang the
calling thread.

To reproduce this, write the following scripts (this was a small test
case I came up with - maybe there's something simpler):
[scripts snipped] Run ./tryhup.bash. It will sit in an idle spin. Monitor the files
/tmp/hup.out and /tmp/lup.out. Hit Ctrl-C on tryhup to kill it. The
python process is still running, but is stalled (the .out files are no
longer changing).

If you remove the above labeled line, however, this doesn't happen.

Can anybody please acknowledge this bug? Any temporary workarounds to
this problem? Thanks in advance for looking into this and for hearing
me in!


I tried these scripts on Ubuntu 5.10 and did not see the problem you
are experiencing. The script continues to run (printing dashes to the
console), and hup.out/lup.out are also updated continuously.

What's your configuration? Also, note that the logging module merely
opens the stream passed to the StreamHander for output, so check if in
your configuration you get a hang just doing a write to sys.stderr.

Best regards,

Vinay Sajip

Feb 14 '06 #2

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

Similar topics

2
by: Thomas Schulz | last post by:
Hello, I'm using the logging package from python 2.3 on RH linux. Everything in the test program below works fine if we just use the log configuration with 'logging.basicConfig'. For the...
2
by: rh0dium | last post by:
Hi all, So I have a slice of code which calls other python code. I have started to take a real liking to the logging module, but I want to extend this into the called python code. I have no...
1
by: Maksim Kasimov | last post by:
hello in my modules, I'm using logging module, doing thus (there is a few modules): in module1.py: hdl = logging.StreamHandler() fmt =...
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...
0
by: robert | last post by:
As more and more python packages are starting to use the bloomy (Java-ish) 'logging' module in a mood of responsibility and as I am not overly happy with the current "thickener" style of usage, I...
7
by: flupke | last post by:
Hi, i'm getting errors with the log module concerning RotatingFileHandler. I'm using Python 2.4.3 on Windows XP SP2. This used to work in previous python versions but since i upgraded to 2.4.3...
3
by: Gary Jefferson | last post by:
I've written a logging.filter and would like to use doctest on it (using a StreamHandler for stdout), but this doesn't seem possible. Output from the logger seems to disappear (running the doctest...
4
by: samwyse | last post by:
In the Python 2.5 Library Reference, section 14.5.3 (Logging to multiple destinations), an example is given of logging to both a file and the console. This is done by using logging.basicConfig()...
1
by: Victor Lin | last post by:
Hi, I'm writting a application using python standard logging system. I encounter some problem with unicode message passed to logging library. I found that unicode message will be messed up by...
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
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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.