[issue4705] python3.0 -u: unbuffered stdout
Mark Dickinson
report at bugs.python.org
Sun Jan 25 22:25:20 CET 2009
Mark Dickinson <dickinsm at gmail.com> added the comment:
> since I don't see how the behaviour can differ for a read-only
> non-seekable stream.
Unless I'm misunderstanding you (quite likely), I think one *can* get
different results with buffered and unbuffered stdin.
For example, on my machine, if I create the following script:
#!/usr/bin/python -u
import sys
print sys.stdin.readline()
and name it test.py, I get the following result in an OS X Terminal
running bash:
dickinsm$ ls python_source/trunk/Objects/ | (./test.py; ./test.py)
abstract.c
boolobject.c
Whereas if I remove the '-u' from the shebang line I just get:
dickinsm$ ls python_source/trunk/Objects/ | (./test.py; ./test.py)
abstract.c
I'm not 100% sure that I understand exactly what's going on here, but it's
something like the following: in the first (unbuffered) case, the
stdin.readline call of the first ./test.py only reads one line from stdin,
leaving the rest intact; so the second ./test.py also gets to output a
line. In the second case some larger amount of stdin (1024 bytes?) is
immediately slurped into the stdin buffer for the first Python process, so
the second ./test.py doesn't get anything.
----------
nosy: +marketdickinson
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4705>
_______________________________________
More information about the Python-bugs-list
mailing list