mkaz / termgraph

a python command-line tool which draws basic graphs in the terminal
MIT License
3.15k stars 164 forks source link

BrokenPipeError when piping to head #80

Closed danielhoherd closed 3 years ago

danielhoherd commented 3 years ago

Description

When piping termgraph to head, and I assume other commands that do not process the whole pipe stream, a BrokenPipeError is raised.

How to reproduce

$ cat <<EOF | termgraph | head -n 5
2021-05-30      15
2021-05-29      20
2021-05-28      21
2021-05-27      19
2021-05-26      19
2021-05-25      18
2021-05-24      18
2021-05-23      19
2021-05-22      19
EOF

2021-05-30: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 15.00
2021-05-29: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 20.00
2021-05-28: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 21.00
2021-05-27: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 19.00
Traceback (most recent call last):
  File "/home/dho/.local/bin/termgraph", line 8, in <module>
    sys.exit(main())
  File "/home/dho/.local/lib/python3.8/site-packages/termgraph/termgraph.py", line 130, in main
    chart(colors, data, args, labels)
  File "/home/dho/.local/lib/python3.8/site-packages/termgraph/termgraph.py", line 487, in chart
    for row in horiz_rows(
  File "/home/dho/.local/lib/python3.8/site-packages/termgraph/termgraph.py", line 282, in horiz_rows
    print(label, end="")
  File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 41, in write
    self.__convertor.write(text)
  File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 162, in write
    self.write_and_convert(text)
  File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 190, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 196, in write_plain_text
    self.wrapped.flush()
BrokenPipeError: [Errno 32] Broken pipe
Exception ignored in: <colorama.ansitowin32.StreamWrapper object at 0x7f9016207310>
BrokenPipeError: [Errno 32] Broken pipe

Test env

$ termgraph --version
termgraph v0.4.2
$ python3 --version --version
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0]
$ uname -a
Linux litten 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux