如何为python 3.6.7强制行缓冲?

时间:2019-02-27 19:14:15

标签: linux python-3.x

在Ubuntu上运行命令时,我使用“ stdbuf -oL”强制行缓冲。这适用于Python 2.7,但似乎不适用于Python 3.6.7:

# test_buf.py
import time 
for i in range(10):  
  print('a')  
  time.sleep(1)

我运行命令:stdbuf -oL python test_buf.py> output.txt

使用Python 3.6.7运行时,仅在解释器存在后才更新output.txt文件。使用Python 2.7运行时,每写一行都会更新output.txt。
1.知道为什么stdbuf不适用于Python 3.6.7吗?
2.是否有其他替代方式来强制行缓冲(不是在Python进程中)?

0 个答案:

没有答案