Python 到 fifo 不会刷新

问题描述

在终端 1

#> mkfifo /tmp/f
#> python -c 'import sys
while True:
  sys.stdout.write(sys.stdin.readline ())
  sys.stdout.flush()
' >/tmp/f

在终端 2

#> tail -f /tmp/f

我在终端 1 中输入,希望每一行都立即出现在终端 2 中,但这并没有发生。当我 ctrl-c 运行 Python 脚本时,我输入的所有行突然出现在终端 2 中。

我认为显式 flush() 会导致 tail 立即拿起所有行,但没有。

为什么不呢?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)