Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80279

Misunderstanding buffering - flushing isn't

Date 2014-11-05 10:44 -0600
Subject Misunderstanding buffering - flushing isn't
From Skip Montanaro <skip.montanaro@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.15506.1415205889.18130.python-list@python.org> (permalink)

Show all headers | View raw


I've been developing a little web server. The request handler
subclasses SimpleHTTPRequestHandler. It has a do_GET method which
figures out what work to actually do, then ends with this:

    def do_GET(self):
        ...
        sys.stdout.flush()
        sys.stderr.flush()

As it's still being actively developed, I've been dumping all sorts of
diagnostic prints to stdout and stderr. I've been running it directly
in a terminal window (this is an openSuSE system), but wanted to
capture stdout and stderr for post-mortem analysis, so I wrote this
little shell script:

    #!/bin/bash

    PORT=${1:-8008}
    BASE=$(dirname $0)

    echo port=$PORT pid=$$ > ${PORT}.stdout

    while true ; do
	python ${BASE}/httpserver.py $PORT >> ${PORT}.stdout 2> ${PORT}.stderr
	sleep 1
    done

I figured everything would be flushed to the respective .stdout and
.stderr files at the end of every request, but that appears not to be
the case. Do I have to run the python command with the -u flag to
guarantee each request's output is immediately available in the output
file at the end of each request?

Thx,

Skip

Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Misunderstanding buffering - flushing isn't Skip Montanaro <skip.montanaro@gmail.com> - 2014-11-05 10:44 -0600
  Re: Misunderstanding buffering - flushing isn't Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2014-11-05 18:29 +0100
    Re: Misunderstanding buffering - flushing isn't Skip Montanaro <skip.montanaro@gmail.com> - 2014-11-05 11:54 -0600
    Re: Misunderstanding buffering - flushing isn't Chris Angelico <rosuav@gmail.com> - 2014-11-06 05:03 +1100
    Re: Misunderstanding buffering - flushing isn't Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-06 02:14 +0000

csiph-web