在subprocess.Popen中,bufsize适用于哪个文件?
我需要在调用 Popen
的时候,把 stderr
流设置为行缓冲。我发现了 bufsize
这个参数,但它没有说明这个参数到底是应用于哪一个文件(stdin
、stdout
还是 stderr
)。
bufsize
参数修改的是哪个文件?- 我该如何修改其他文件的缓冲模式?
1 个回答
3
使用源代码,卢克 :-) /usr/lib/python2.7/subprocess.py
:
if p2cwrite is not None:
self.stdin = os.fdopen(p2cwrite, 'wb', bufsize)
if c2pread is not None:
if universal_newlines:
self.stdout = os.fdopen(c2pread, 'rU', bufsize)
else:
self.stdout = os.fdopen(c2pread, 'rb', bufsize)
if errread is not None:
if universal_newlines:
self.stderr = os.fdopen(errread, 'rU', bufsize)
else:
self.stderr = os.fdopen(errread, 'rb', bufsize)
所以看起来它在所有这些地方都使用了 bufsize
,没有办法具体指定。