[ python-Bugs-1431253 ] Logging hangs thread after detaching a StreamHandler's termi

SourceForge.net noreply at sourceforge.net
Fri Feb 17 08:17:20 CET 2006


Bugs item #1431253, was opened at 2006-02-13 22:07
Message generated for change (Comment added) made by yangzhang
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1431253&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
>Status: Pending
Resolution: Works For Me
Priority: 5
Submitted By: Yang Zhang (yangzhang)
Assigned to: Vinay Sajip (vsajip)
Summary: Logging hangs thread after detaching a StreamHandler's termi

Initial Comment:
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!

----------------------------------------------------------------------

>Comment By: Yang Zhang (yangzhang)
Date: 2006-02-16 23:17

Message:
Logged In: YES 
user_id=1207658

Hi, yes, after I submitted this bug I actually looked into 
logging.StreamHandler, and found that its code was not too 
complicated (as with everything Python :).

I tried some more experiments, and found that the problem is 
in stderr, which throws an exception. The problem was that I 
couldn't see the exception (and didn't suspect that's what 
was happening), so the fact that the next line never came 
out led me to believe that the thread froze.

Is stderr supposed to raise an exception like this? Is this 
a bug?

Unfortunately, it's hard for me to tell what's going on 
(what the exception is that's being thrown). How do I tell 
what it's raising? (stderr is no longer avail. after all) I 
don't know how to catch an exception of any type and (say) 
print its str or repr value to a file so that I can tell 
what's going on.

----------------------------------------------------------------------

Comment By: Yang Zhang (yangzhang)
Date: 2006-02-16 23:16

Message:
Logged In: YES 
user_id=1207658

Hi, yes, after I submitted this bug I actually looked into 
logging.StreamHandler, and found that its code was not too 
complicated (as with everything Python :).

I tried some more experiments, and found that the problem is 
in stderr, which throws an exception. The problem was that I 
couldn't see the exception (and didn't suspect that's what 
was happening), so the fact that the next line never came 
out led me to believe that the thread froze.

Is stderr supposed to raise an exception like this? Is this 
a bug?

Unfortunately, it's hard for me to tell what's going on 
(what the exception is that's being thrown). How do I tell 
what it's raising? (stderr is no longer avail. after all) I 
don't know how to catch an exception of any type and (say) 
print its str or repr value to a file so that I can tell 
what's going on.

----------------------------------------------------------------------

Comment By: Vinay Sajip (vsajip)
Date: 2006-02-16 17:04

Message:
Logged In: YES 
user_id=308438

Please provide more information about your OS - I ran these
scripts on Ubuntu 5.10 and did not see the problems you
mention. The script continues to run (printing dashes to the
console), and hup.out/lup.out are also updated continuously. 

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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1431253&group_id=5470


More information about the Python-bugs-list mailing list