[Python-3000] print() flushing problem.

Wojciech Walczak wojtek.gminick.walczak at gmail.com
Wed Nov 7 17:45:42 CET 2007


2007/11/7, Daniel Stutzbach <daniel at stutzbachenterprises.com>:

> print() shouldn't flush if there isn't a newline, unless the buffer is
> full or the user calls flush().

So the buffer size in py3k is 1 byte long? Try this as a script in py3k:

-----------------
import time

print('xx',end='')
time.sleep(3)
print('x',end='')
time.sleep(3)
-----------------

First print() will flush immediately even though there is no newline
and flush is not called, while second print() will flush after second
sleep.
What I am saying is that print() is not flushing immediately when
string is 1 byte long, but when it is longer - then print() is
flushing immediately. It works that way both for interpreter and
scripts.

> The patch you suggest would cause a flush after *every* write with
> print, which would cause a very significant performance hit on
> programs that do a lot of writing to standard output (especially if
> standard output is a pipe).

No, it is calling flush only when the 'end' in print() is set.
Otherwise (end==NULL or end==Py_None) it just prints newline as it was
doing before. Anyway - I agree that it is a hit for performance and as
I said before, I think that the problem lies somewhere deeper. Any
clues?


Wojciech Walczak


More information about the Python-3000 mailing list