python-progressbar
python-progressbar copied to clipboard
How to do nested progress bars?
e.g. tqdm has some: https://github.com/tqdm/tqdm#nested-progress-bars
Thanks to @paulo-raca we have a basic version of a multi-bar: https://github.com/WoLpH/python-progressbar/pull/208
But the proper version, similar to what tqdm has isn't there yet: https://github.com/WoLpH/python-progressbar/issues/189 I've made a basic attempt some time ago but it is not a trivial fix and I'm just too limited in time to get into it any time soon. It's really high on my wishlist though...
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I've properly added the feature of multiple progressbars now.
The approach is a bit different from tqdm
but I personally think this is a more obvious (although slightly more verbose) approach.
The MultiBar
can be used both using a with MultiBar() as multibar:
and using a regular instance. You can manually render on demand using multibar.render()
if you already have a display loop. If you want to have it render in the background you can use multibar.start()
to run it as a background thread.
I'm still testing with it but I believe it works quite well. Usage: https://github.com/wolph/python-progressbar#multiple-threaded-progressbars
import random
import threading
import time
import progressbar
BARS = 5
N = 50
def do_something(bar):
for i in bar(range(N)):
# Sleep up to 0.1 seconds
time.sleep(random.random() * 0.1)
# print messages at random intervals to show how extra output works
if random.random() > 0.9:
bar.print('random message for bar', bar, i)
with progressbar.MultiBar() as multibar:
for i in range(BARS):
# Get a progressbar
bar = multibar[f'Thread label here {i}']
# Create a thread and pass the progressbar
threading.Thread(target=do_something, args=(bar,)).start()
You can add your custom progressbars to a MultiBar
instance like this:
multi['Some label'] = your_progress
The new version with nested progressbar support has been released :)