New submission from STINNER Victor <victor.stin...@haypocalc.com>: I like and I need an "unbuffered" standard output which was provided by -u command line option (or PYTHONUNBUFFERED environment variable). Current status of -u option in Python3: the option exists and change the buffer size (disable buffering) of the stdin, stdout and stderr file descriptors.
The problem is in initstdio() which creates files with buffering=-1 (default buffer) instead of buffering=0 (no buffering) or buffering=1 (line buffer). But open() enable line buffering of TextIOWrapper is buffering=-1 and the raw file is a tty. Example with py3k trunk: ------------ $ ./python >>> import sys; sys.stdout.line_buffering True $ ./python |cat >>> import sys; sys.stdout.line_buffering False ------------ I would like line buffering when stdout is redirected to a pipe and -u option is used. initstdio() have to be changed to choose buffering option. So it's something like: Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (révision 67870) +++ Python/pythonrun.c (copie de travail) @@ -810,7 +810,12 @@ #endif } else { - if (!(std = PyFile_FromFd(fd, "<stdout>", "w", -1, encoding, + int buffering; + if (1) + buffering = 1; /* line */ + else + buffering = -1; /* default */ + if (!(std = PyFile_FromFd(fd, "<stdout>", "w", buffering, encoding, errors, "\n", 0))) { goto error; } But "if (1)" have to be replaced "if -u option is used" :-) See unbuffered variable of Modules/main.c. ---------- messages: 78102 nosy: haypo severity: normal status: open title: python3.0 -u: unbuffered stdout versions: Python 3.0 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue4705> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com