"print" strange with Sybase module

Chris chris at 2s2iNO_SPAM.com
Sun Jan 28 01:09:59 EST 2001


I've been experiencing this unflushed buffer issue as well when running some
Python programs in the background and redirecting their output to log files.
Is there any way that I could force the buffers to flush somehow?  I am
being plagued by incomplete log files!  Or perhaps there is a better
approach?

Thank you!

Erwin S. Andreasen <erwin at andreasen.com> wrote in message
news:94q0f6$lu5$1 at news.cybercity.dk...
> On Thu, 25 Jan 2001 13:04:10 +0100, Carsten Gaebler wrote:
>
> >The following simple program (sqltest.py) returns about 20 lines of
> >Sybase output when run as "./sqltest.py". But if I say
> >
> >./sqltest.py | tee /tmp/test.txt
> >
> >there is no output and test.txt is empty. What's going wrong? It's
> >Sybase module 0.10 with Python 2.0.
>
> Does your Python interpreter exit before the very end with some fatal
error?
> (do echo $? after you run the script without piping it to see the exit
error
> code, is it 0?).
>
> You see, standard output which "print" prints to is line-buffered when
> connected to a terminal (i.e. the buffer is flushed after each line). When
it
> is run through a pipe, it is block buffered (i.e. the buffer is flushed
after
> 4096 bytes of output has been gathered).
>
> If the program exits unexpectedly (sys.exit(1) or an exception is OK, but
> os._exit(1) or a fatal signal isn't) these buffers will not be flushed.
>
> I can't see a reason to why it would exit that way quietly, but unflushed
> buffers are the first thing that comes to mind when seeing those symptoms.
>
>
> PS: Any Python-users attending Linux Expo in Paris?
>
> --
> =======================================================================
> <erwin at andreasen.com>           Herlev, Denmark       Software Designer
> <URL:http://www.andreasen.org/>       <*>         LASAT^WEicon Networks
> =======================================================================
>





More information about the Python-list mailing list