On 2012-01-13, at 16:34 , anatoly techtonik wrote:
> Posting to python-dev as it is no more relates to the idea of improving
> print().
> 
> 
> sys.stdout.write() in Python 3 causes backwards incompatible behavior that
> breaks recipe for unbuffered character reading from stdin on Linux -
> http://code.activestate.com/recipes/134892/  At first I though that the
> problem is in the new print() function, but it appeared that the culprit is
> sys.stdout.write()
> 
> Attached is a test script which is a stripped down version of the recipe
> above.
> 
> If executed with Python 2, you can see the prompt to press a key (even
> though output on Linux is buffered in Python 2).
> With Python 3, there is not prompt until you press a key.
> 
> Is it a bug or intended behavior? What is the cause of this break?
FWIW this is not restricted to Linux (the same behavior change can
be observed in OSX), and the script is overly complex you can expose
the change with 3 lines

    import sys
    sys.stdout.write('promt>')
    sys.stdin.read(1)

Python 2 displays "prompt" and terminates execution on [Return],
Python 3 does not display anything until [Return] is pressed.

Interestingly, the `-u` option is not sufficient to make
"prompt>" appear in Python 3, the stream has to be flushed
explicitly unless the input is ~16k characters (I guess that's
an internal buffer size of some sort)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to