2

i try to pipe some output from python3 in to dzen2, but dzen wont update.

in bash:

i=0; while true; do; echo $i; (( i++ )); sleep 1; done | dzen2

output terminal:

0
1
2
3...

in python

import time
i=0
while True:
  print(i)
  i+=1
  time.sleep(1)

output terminal:

0
1
2
3...

python3 while.py | dzen2 black empty dzen2-bar

bash-loop.sh | dzen2 black bar which counts from 0 to ...

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Buffering. Buffering. Buffering. – William Pursell May 01 '14 at 12:45
  • When python's output is to a tty, it line buffers stdout. But when its output is a pipe, stdout is block buffered. This means that python is holding all the data until it has a full block (1024 bytes, or 512, or 4192, depending on your system) to write. This is very standard. See: http://stackoverflow.com/questions/107705/python-output-buffering – William Pursell May 01 '14 at 12:49
  • @WilliamPursell: Please convert the comment to an answer. – pilona Jun 13 '14 at 01:06

1 Answers1

1

When python's output is to a tty, it line buffers stdout. But when its output is a pipe, stdout is block buffered. This means that python is holding all the data until it has a full block (1024 bytes, or 512, or 4192, depending on your system) to write. This is very standard. See: stackoverflow.com/questions/107705/python-output-buffering

William Pursell
  • 204,365
  • 48
  • 270
  • 300