Commit 2fa9aa01 authored by Jason Madden's avatar Jason Madden

Merge pull request #542 from romuald/popen-bufsize

subprocess.Popen `bufsize` option actually used
parents 15992102 ff230fb4
......@@ -247,17 +247,17 @@ class Popen(object):
errread = msvcrt.open_osfhandle(errread.Detach(), 0)
if p2cwrite is not None:
self.stdin = FileObject(p2cwrite, 'wb')
self.stdin = FileObject(p2cwrite, 'wb', bufsize)
if c2pread is not None:
if universal_newlines:
self.stdout = FileObject(c2pread, 'rU')
self.stdout = FileObject(c2pread, 'rU', bufsize)
else:
self.stdout = FileObject(c2pread, 'rb')
self.stdout = FileObject(c2pread, 'rb', bufsize)
if errread is not None:
if universal_newlines:
self.stderr = FileObject(errread, 'rU')
self.stderr = FileObject(errread, 'rU', bufsize)
else:
self.stderr = FileObject(errread, 'rb')
self.stderr = FileObject(errread, 'rb', bufsize)
def __repr__(self):
return '<%s at 0x%x pid=%r returncode=%r>' % (self.__class__.__name__, id(self), self.pid, self.returncode)
......
......@@ -159,6 +159,16 @@ class Test(greentest.TestCase):
else:
raise AssertionError('must fail with CalledProcessError')
def test_popen_bufsize(self):
# Test that subprocess has unbuffered output by default
# (as the vanilla subprocess module)
p = subprocess.Popen([sys.executable, '-u', '-c',
'import sys; sys.stdout.write(sys.stdin.readline())'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.stdin.write('foobar\n')
r = p.stdout.readline()
self.assertEqual(r, 'foobar\n')
if __name__ == '__main__':
greentest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment