我需要在 Popen
中设置 stderr
流调用行缓冲。我发现了 bufsize
参数,但它没有说明 3 个参数中的哪一个(stdin
、stdout
、stderr
) 实际应用到的文件。
- 哪个文件执行
bufsize
参数 修改? - 如何修改另一个 文件缓冲模式?
最佳答案
使用源代码,Luke :-) /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
,无法具体说明。
关于python - 在subprocess.Popen中,bufsize适用于哪个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5604204/