[Python-3000] print() flushing problem.

Wojciech Walczak wojtek.gminick.walczak at gmail.com
Thu Nov 8 19:41:25 CET 2007


> Got it! Please, take a look at my patch. It's in the attachment. I am
> still digging in the source, but I think that I have found the core of
> the bug.
> Without that patch "ret=sys.stdout.write('x')" acts in the same way as
> print('x',end=''), which is - it prints nothing. After applying the
> patch it is allright for both sys.stdout.write() and for print().


The other question is why is self.buffer_size set to 1. But I am
leaving it for tomorrow. Now, a few words about performance. For
debugging reasons I have added a simple line to PyObject_Call()
function in Objects/abstract.c:
printf("%s.%s\n", func->ob_type->tp_name, PyEval_GetFuncName(func));
Now, after compiling python and running interpreter with simple
print() call I receive this:

>>> print('!',end='')
builtin_function_or_method.print
method.write
function.write
function.closed
function.closed
builtin_function_or_method.ascii_encode
function.closed
function.closed
!method.write   # here it goes again for 'end' parameter
function.write
function.closed
function.closed
builtin_function_or_method.ascii_encode
function.closed
builtin_function_or_method.displayhook
>>>

Isn't it checking if stream is closed a bit too often?

Wojtek Walczak


More information about the Python-3000 mailing list