verigak / progress

Easy to use progress bars for Python
ISC License
1.41k stars 179 forks source link

Does it work with jupyter lab? #83

Open tamkaho opened 4 years ago

tamkaho commented 4 years ago

It doesn't seem to be showing on Jupyter lab for me. Is there a way to get it to work?

zhaowb commented 4 years ago

Need to skip check_tty, also skip hide_cursor so not to print esc commands: example:

from progress.bar import Bar
with Bar(message='Prog', max=20, check_tty=False, hide_cursor=False) as bar:
    for _ in range(20):
        time.sleep(1)
        bar.next()
    bar.finish()  # prints an empty line, not necessary

Update: without hide_cursor=False there is no visible difference on screen but from source code it prints esc commands which are not necessary in Jupyter.

zhaowb commented 4 years ago

Also jupyter seems need a chance to get '\r' right (got hint here) ~So use in jupyter better use a time.sleep(0) to let jupyter render '\r' right.~ Otherwise the output may corrupt for long runs.

Update: Sorry this doesn't really work. It might help in shorter runs, but in long runs (191783 in my test, update() every time) it's still ugly.

from progress.bar import Bar
with Bar(message='Prog', max=20, check_tty=False, hide_cursor=False) as bar:
    for _ in range(20):
        time.sleep(1)
        bar.next()
        time.sleep(0)   # <<< add this
    bar.finish()  # prints an empty line, not necessary
visika commented 3 months ago

The same issue stands using marimo, and the suggested fix works too