This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Joe.Borg
Recipients Joe.Borg
Date 2013-08-28.09:19:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1377681564.92.0.926371389199.issue18868@psf.upfronthosting.co.za>
In-reply-to
Content
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:

#!/bin/python3
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:
        p.stdin.write(bytes("test\n", encoding="utf-8"))
        time.sleep(10)

Where unbuffered_test.sh is:
#!/bin/sh
read INPUT
echo $INPUT
exit 0

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.
History
Date User Action Args
2013-08-28 09:19:24Joe.Borgsetrecipients: + Joe.Borg
2013-08-28 09:19:24Joe.Borgsetmessageid: <1377681564.92.0.926371389199.issue18868@psf.upfronthosting.co.za>
2013-08-28 09:19:24Joe.Borglinkissue18868 messages
2013-08-28 09:19:24Joe.Borgcreate