[New-bugs-announce] [issue18868] Python3 unbuffered stdin
report at bugs.python.org
Wed Aug 28 11:19:24 CEST 2013
New submission from Joe Borg:
I'm in need of an unbuffered stdin for Python3. Using the '-u' flag worked fine in Python2. But, it seems, Python3's stdin is always buffered; as seen in http://bugs.python.org/issue4705.
This is not always desirable. For example:
import os, subprocess, time
with open("%s/unbuffered_test.log" % (os.getenv("HOME")), "w") as f:
with subprocess.Popen(["%s/unbuffered_test.sh" % (os.getenv("HOME"))], stdin=subprocess.PIPE, stdout=f, stderr=f) as p:
Where unbuffered_test.sh is:
Running with -u in Python2 sees the log file populated before the 10 seconds are up. This isn't the case in Python3. This making controlling applications, using subprocess, basically impossible; without putting p.stdin.flush() after each command (which does work in the example above).
I ran this example in Python3.3.2.
title: Python3 unbuffered stdin
versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce