Logging hangs thread after detaching a StreamHandler's terminal

python-list.overbored at spamgourmet.com python-list.overbored at spamgourmet.com
Tue Feb 14 01:03:05 EST 2006


Apologies, I seem to have sent this to the wrong list. (Though now
that it's out here...any answers would be most welcome. :)

On 2/14/06, I 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):
>
> $ 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!
>




More information about the Python-list mailing list