Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80279 > unrolled thread
| Started by | Skip Montanaro <skip.montanaro@gmail.com> |
|---|---|
| First post | 2014-11-05 10:44 -0600 |
| Last post | 2014-11-06 02:14 +0000 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.python
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
| From | Skip Montanaro <skip.montanaro@gmail.com> |
|---|---|
| Date | 2014-11-05 10:44 -0600 |
| Subject | Misunderstanding buffering - flushing isn't |
| Message-ID | <mailman.15506.1415205889.18130.python-list@python.org> |
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
[toc] | [next] | [standalone]
| From | Irmen de Jong <irmen.NOSPAM@xs4all.nl> |
|---|---|
| Date | 2014-11-05 18:29 +0100 |
| Message-ID | <545a5e88$0$2882$e4fe514c@news.xs4all.nl> |
| In reply to | #80279 |
On 5-11-2014 17:44, Skip Montanaro wrote: > As it's still being actively developed, I've been dumping all sorts of > diagnostic prints to stdout and stderr. Any reason you're not using the logging module and get it all nicely dumped into a log file instead? (asks he who regularly inserts prints himself when doing a debugging task) Irmen
[toc] | [prev] | [next] | [standalone]
| From | Skip Montanaro <skip.montanaro@gmail.com> |
|---|---|
| Date | 2014-11-05 11:54 -0600 |
| Message-ID | <mailman.15510.1415210069.18130.python-list@python.org> |
| In reply to | #80282 |
On Wed, Nov 5, 2014 at 11:29 AM, Irmen de Jong <irmen.NOSPAM@xs4all.nl> wrote: > Any reason you're not using the logging module and get it all nicely dumped into a log > file instead? I'm an old fart. What can I say? BITD, (as Irmen is well aware, being about as old as I am in Python years), print was all we had. (We also walked uphill to school in both directions, in the snow.) While I use the logging module in other contexts, I never really liked it, and generally use it grudgingly. Skip
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-11-06 05:03 +1100 |
| Message-ID | <mailman.15512.1415210631.18130.python-list@python.org> |
| In reply to | #80282 |
On Thu, Nov 6, 2014 at 4:54 AM, Skip Montanaro <skip.montanaro@gmail.com> wrote: > I'm an old fart. What can I say? BITD, (as Irmen is well aware, being > about as old as I am in Python years), print was all we had. (We also > walked uphill to school in both directions, in the snow.) While I use > the logging module in other contexts, I never really liked it, and > generally use it grudgingly. I have nothing against print... as long as it's a function. I don't like the arcane notations shoehorned into the print statement (the >> syntax always trips me up, I'm never sure whether to put it at the beginning or the end - it's ugly either way), but the function behaves nicely. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-11-06 02:14 +0000 |
| Message-ID | <mailman.15525.1415240097.18130.python-list@python.org> |
| In reply to | #80282 |
On 05/11/2014 17:54, Skip Montanaro wrote: > On Wed, Nov 5, 2014 at 11:29 AM, Irmen de Jong <irmen.NOSPAM@xs4all.nl> wrote: >> Any reason you're not using the logging module and get it all nicely dumped into a log >> file instead? > > I'm an old fart. What can I say? BITD, (as Irmen is well aware, being > about as old as I am in Python years), print was all we had. (We also > walked uphill to school in both directions, in the snow.) While I use > the logging module in other contexts, I never really liked it, and > generally use it grudgingly. > > Skip > My approach was much like yours but I was converted a couple of years ago. Sadly both the name of the author and the title of the article left, as the late, great Spike Milligan said in one of his books, "an indelible blank on my mind" :) However in an attempt to show that you can teach a fellow old fart new tricks could an article like this help http://fruch.github.io/2014/11/06/taming-the-logging-formatter/ ? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web