[issue8213] Python 3 ignored PYTHONUNBUFFERED and -u

Antoine Pitrou report at bugs.python.org
Tue Mar 23 16:33:51 CET 2010


Antoine Pitrou <pitrou at free.fr> added the comment:

In the current state of affaires this is more of a documentation issue.

Python 3 doesn't support totally unbuffered text I/O (and standard streams are open in text mode). What `-u` and PYTHONUNBUFFERED do is that the binary layer of standard streams is unbuffered, but the text layer is still line-buffered (if in a tty).

"python --help" gives you an accurate description:

-u     : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
         see man page for details on internal buffering relating to '-u'

Also, you can try out:

python3 -u -c  'import time, sys; sys.stdout.buffer.write(b"b"); time.sleep(1); sys.stdout.buffer.write(b"\n")'

To explicitly flush the text layer, you can use the flush() method.

----------
priority:  -> normal

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8213>
_______________________________________


More information about the Python-bugs-list mailing list