Alive_bar() crashes when printing bytes (such as with click.echo)
See original GitHub issueHi, I’m using click.echo to print messages as the bar is being displayed and I’m running into an error. Check out the example below:
import click
import time
from alive_progress import alive_bar
# First example with standard print function, runs fine
# with alive_bar() as bar:
# for i in range(100):
# print(f'Printing iteration {i} with print')
# time.sleep(0.05)
# bar()
# Now, with click stdout
with alive_bar() as bar:
for i in range(100):
click.echo(f'Printing iteration {i} with click.echo')
time.sleep(0.05)
bar()
which gives me the error:
on 0: Traceback (most recent call last):
File "venv/lib/python3.8/site-packages/alive_progress/core/progress.py", line 249, in __alive_bar
yield bar
on 0: File "alive_progress_bug.py", line 15, in <module>
click.echo(f'Packet no. {i}')
on 0: File "venv/lib/python3.8/site-packages/click/utils.py", line 298, in echo
file.write(out) # type: ignore
on 0: File "venv/lib/python3.8/site-packages/alive_progress/core/hook_manager.py", line 32, in flush
write(stream, '\n')
on 0: File "venv/lib/python3.8/site-packages/alive_progress/core/hook_manager.py", line 45, in write
nested = ''.join(line or ' ' * len(header) for line in buffer)
on 0: TypeError: sequence item 0: expected str instance, bytes found
on 0: During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "alive_progress_bug.py", line 18, in <module>
bar()
on 0: File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
on 0: File "venv/lib/python3.8/site-packages/alive_progress/core/progress.py", line 251, in __alive_bar
stop_monitoring()
on 0: File "venv/lib/python3.8/site-packages/alive_progress/core/progress.py", line 151, in stop_monitoring
hook_manager.uninstall()
on 0: File "venv/lib/python3.8/site-packages/alive_progress/core/hook_manager.py", line 70, in uninstall
flush_buffers()
on 0: File "venv/lib/python3.8/site-packages/alive_progress/core/hook_manager.py", line 28, in flush_buffers
flush(stream)
on 0: File "venv/lib/python3.8/site-packages/alive_progress/core/hook_manager.py", line 32, in flush
write(stream, '\n')
on 0: File "venv/lib/python3.8/site-packages/alive_progress/core/hook_manager.py", line 45, in write
nested = ''.join(line or ' ' * len(header) for line in buffer)
on 0: TypeError: sequence item 0: expected str instance, bytes found
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Utilities — Click Documentation (8.1.x)
The most obvious helper is the echo() function, which in many ways works like the Python print statement or function. The main difference...
Read more >WritePrinter fails with "a bytes-like object is required, not 'str ...
The error started after rewriting Qt code that prints a special QString to a DataMax printer in PLZ mode into Python. We originally...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think we should decode the binary data. It’s not like the program will completely mess up - it’ll just crash, exactly like it does now. It wouldn’t be reducing compatibility.
Hey, it is released! #131 Take a look at the new readme for details! 🎉