[Python-3000] print() flushing problem.

Wojciech Walczak wojtek.gminick.walczak at gmail.com
Fri Nov 9 11:32:16 CET 2007

2007/11/9, Guido van Rossum <guido at python.org>:

> Well, passing '1' as the buffer size to open() is supposed to set the
> buffer size to the default value (typically 8K)

OK, my new patch does that. At the momment it is buffering for
interactive mode as well as for scripts instead of buffering only for
the latter.

Python 3.0a1 (py3k, Nov  9 2007, 11:09:49)
[GCC 4.1.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print('python is flushing when there\' a new line')
python is flushing when there' a new line
>>> print('python is not flushing when new line is gone',end='')
>>> print('')
python is not flushing when new line is gone
>>> ret=sys.stdout.write('python is not flushing when new line is gone')
>>> sys.stdout.flush()
python is not flushing when new line is gone>>><ENTER>
>>> ret=sys.stdout.write('python is flushing when there\s a new line\n')e
python is flushing when there\s a new line

But, is this really what we want to do? When I run that code:
#include <stdio.h>
#include <string.h>
int main(void)
   char *buf="write() is flushing!";
   char *buf2="x";
   // printf("printf() requires a new line to flush");
   return 0;

each write() is writing before sleep() even though there's no flush().
Do we want to ask every programmer to flush everytime there's no new line?
If not, python should flush for every string > 0 bytes, than for
string > 1 byte.

> *and* set a special
> flag that forces a flush() whenever a line end is written. But this
> isn't implemented; instead, it just flushes after each character...

Isn't it rather flushing after each print() or write() call?

Wojtek Walczak
-------------- next part --------------
A non-text attachment was scrubbed...
Name: py3k-print_2nd.patch
Type: application/octet-stream
Size: 420 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-3000/attachments/20071109/ad557044/attachment.obj 

More information about the Python-3000 mailing list