how do i disable buffered output, like Perl's '$|=1'?

floR flor_pino at hotmail.com
Sun Jan 14 14:49:28 EST 2001


sys.stdout.flush() did the trick!
Thanks (and to the others who responded) for the extremely fast reply.


Fredrik Lundh <fredrik at effbot.org> schreef in berichtnieuws
fQl86.6559$AH6.979259 at newsc.telia.net...
> floR wrote:
> > Not exactly what I meant, I think.
>
> It does exactly what you want -- but sure, there are
> other ways to do the same thing:
>
> > Okay, what I want to do in particular, is to send 'print' commands to
the
> > browser in intervals, without buffering, something like the following:
> >
> + import sys
> > print 'Content-type: text/html\n\n'
> > countdown = 10
> > while countdown:
> >     print countdown
> >     countdown = countdown - 1
> +     sys.stdout.flush() # flush output buffers
> >     sleep(1)
> >
> > so that the countdown seems to happen in your browser, instead of
waiting
> > for 10 seconds for the string '10 9 8 7 6 5 4 3 2 1' to appear.
>
> (this assumes that your server sends data to the client
> as soon it arrives from the CGI script, of course).
>
> Cheers /F
>
>





More information about the Python-list mailing list