Unbuffered stdout

Bjorn Pettersen bjorn at roguewave.com
Mon Nov 29 17:47:22 CET 1999


> leon <leonar_n at epita.fr> wrote:
> > I'm developping an IRC like software which must work on the 
> Web. I can't use
> > Java, and I'm using Python to program the CGI. But, I have 
> a big problem : I
> > don't know how to make the stdout unbuffered.
> > I tried to make some
> >     sys.stdout.write("test")
> >     sys.stdout.flush()
> > but it don't work.
> 
> looks fine to me.  maybe something else
> is wrong?
> 
> anyway, you could try running the inter-
> preter with the -u option:
> 
> $ python -?
> Unknown option: -?
> usage: python [option] ... [-c cmd | file | -] [arg] ...
> Options and arguments (and corresponding environment variables):
> ...
> -u     : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)
> ...
> 
> </F>

Note that some webservers automatically buffer cgi output until the cgi
closes stdout.  To the best of my knowledge there are no pretty workarounds
for this...  You should check your webserver's docs to see if this is the
case though.

--bjorn




More information about the Python-list mailing list