question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Alive_bar() crashes when printing bytes (such as with click.echo)

See original GitHub issue

Hi, 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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
TheTechRobocommented, Oct 19, 2021

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.

0reactions
rsalmeicommented, Feb 2, 2022

Hey, it is released! #131 Take a look at the new readme for details! 🎉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found