将python3输出导入dzen2

将python3输出导入dzen2,python,linux,pipe,Python,Linux,Pipe,我尝试将python3的一些输出导入到dzen2,但dzen不会更新 在bash中: i=0; while true; do; echo $i; (( i++ )); sleep 1; done | dzen2 输出端子: 0 1 2 3... 0 1 2 3... 用python import time i=0 while True: print(i) i+=1 time.sleep(1) 输出端子: 0 1 2 3... 0 1 2 3... python3 whil

我尝试将python3的一些输出导入到dzen2,但dzen不会更新

在bash中:

i=0; while true; do; echo $i; (( i++ )); sleep 1; done | dzen2
输出端子:

0
1
2
3...
0
1
2
3...
用python

import time
i=0
while True:
  print(i)
  i+=1
  time.sleep(1)
输出端子:

0
1
2
3...
0
1
2
3...
python3 while.py | dzen2 黑色空dzen2条

bash-loop.sh|dzen2
黑色条,计数范围从0到…

当python的输出是tty时,它是行缓冲区stdout。但当其输出是管道时,stdout是块缓冲的。这意味着python将保存所有数据,直到它有一个完整的块(1024字节,或512字节,或4192字节,取决于您的系统)要写入为止。这是非常标准的。请参阅:stackoverflow.com/questions/107705/python-output-buffering

buffering。缓冲。当python的输出是tty时,它将行缓冲标准输出。但当其输出是管道时,stdout是块缓冲的。这意味着python将保存所有数据,直到它有一个完整的块(1024字节,或512字节,或4192字节,取决于您的系统)要写入为止。这是非常标准的。请看:@williampersell:请将评论转换为答案。