New submission from Geoffrey Bache <gjb1...@users.sourceforge.net>:

The default buffering of standard output and standard error has changed in 
Python 3.x with respect to Python 2.x, and I have been unable to find decent 
documentation of either the current behaviour, or the change.

(See also 
http://groups.google.com/group/comp.lang.python/browse_thread/thread/43476d4682059f53#)

Part 1 - the change
-------------------
>From rude experiment it seems that:
a) In Python 2.x, standard error was always unbuffered while standard
output was buffered by default.  In python3, both are buffered. In
both cases, "buffered" means line-buffered when writing to the console
and not line-buffered when redirected to files.
b) In Python 2.x, the "-u" flag meant everything was totally
unbuffered. In Python 3.x, it means that both stdout and stderr are
line-buffered also when redirected to files. 

One important consequence of (a) is, if stderr is redirected
to a file, your program throws an exception and is then subsequently terminated 
with SIGTERM, you will not see the exception. This will not be expected for 
someone used to the Python 2.x behaviour.

"What's New in Python 3.0" has this to say about the change (in the section 
marked "Changes Already Present In Python 2.6"

"# PEP 3116: New I/O Library. The io module is now the standard way of doing 
file I/O, and the initial values of sys.stdin, sys.stdout and sys.stderr are 
now instances of io.TextIOBase. [...]"

This seems wrong in that, while the io module was present in Python 2.6, the 
change noted to sys.stdin, sys.stdout and sys.stderr was not.
Also, it is far from obvious from this note that any externally observable 
behaviour has changed.

I suggest changing this to 
a) note the buffering changes listed above
b) note the change in meaning of the -u flag
c) Move this to its own section which is not part of changes to Python 2.6 
(it's OK to keep the note about the new io module there)

Part 2 - the behaviour
----------------------
a) The documentation for "sys.stdout" and "sys.stderr" does not say anything 
about their default buffering properties in various situations, nor how this 
can modified by setting the "-u" flag.

b) The documentation for "-u" is misleading:
"Force the binary layer of the stdin, stdout and stderr streams (which
is available as their buffer attribute) to be unbuffered. The text I/O
layer will still be line-buffered." 

The "still" in the last sentence is only relevant when stdout/stderr are 
writing to the console. If they are redirected to file, "-u" *modifies the 
behaviour such that* the text I/O layer will be line-buffered.

----------
assignee: docs@python
components: Documentation
messages: 149408
nosy: docs@python, gjb1002
priority: normal
severity: normal
status: open
title: Improve documentation of stdout/stderr buffering in Python 3.x
type: behavior
versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13597>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to