Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Progress Bar Support #31

Open
bmbouter opened this issue Aug 20, 2016 · 6 comments
Open

Multiple Progress Bar Support #31

bmbouter opened this issue Aug 20, 2016 · 6 comments

Comments

@bmbouter
Copy link

I am interested in having multiple progress bars work. Can someone give me a pointer on how to start on this? This is important when reporting the state of a pipeline which is doing a count of work at each stage but all stages are executing in parallel.

Here is an example of my current problem. I want to update both bars in one loop and then finalize them both using this code:

from time import sleep

from progress.bar import Bar

bar = Bar('Downloading', max=20)
bar2 = Bar('Processing', max=20)

for i in range(20):
    sleep(0.2)
    bar.next()
    bar2.next()
bar.finish()
bar2.finish()

It produces this output:

Processing |################################| 20/20

You only are shown bar2 since it did it's update last. How can multiple bar support be added to this codebase?

@verigak
Copy link
Owner

verigak commented Aug 24, 2016

Unfortunately this is not easy to achieve with the current design. The way it works is that it moves the cursor back and overwrites the text on the same line.

I'm leaving this open in case anyone wants to give it a try.

@bmbouter
Copy link
Author

bmbouter commented Sep 3, 2016

Actually I think the current design may be ok. In thinking more about this, DNF has a great example of using 1 progress bar to show multiple progress bars. It only shows 1 progress bar and rotates the name every second or 2 seconds maybe. For DNF I think the progress is on the download of all packages (say 100) even though only 4 will download concurrently. I guess we could do the same thing to aggregate all of the work for a collection of progress bars.

I'm wondering what (if anything) needs to be added to this project to easily accomplish this aggregated progress bar use case. I hope to make a fake example of the dnf look and feel with the existing library to see how hard it is. I'll post my code back here.

@saraislet
Copy link

What do you think about making another parent class of Bar for Collection to which you could add Bars, and put the WritelnMixin onto the Collection, so that Collection would appropriately handle clearln (i.e., print('\r\x1b[K')), writeln, and finish for any child instances attached to it?

Use would be something like:

bars = Collection()
download_bar = Bar('Downloading', max=20)
install_bar = Bar('Installing', max=20)
bars.extend(download_bar, install_bar)

I'm not sure I can work on this for the next few weeks, but in mid-March I could probably commit some time to working on it.

@verigak
Copy link
Owner

verigak commented Feb 9, 2018

Since these days I don't have much time to work on this, I'm generally hesitant merging big changes. If however you think you can pull this off with minimal disruption and in a backwards compatible way I would be interested in merging it.

@bmbouter
Copy link
Author

bmbouter commented Feb 9, 2018

@saraislet would download_bar and install_bar be shown on top of each other? Or would it do the rotating bar style like dnf? I can see value in both.

I don't understand much about how the line unwinding works and if that is capable of doing it for many lines or not.

@rsalmei
Copy link

rsalmei commented Aug 23, 2019

My new progressbar doesn't support this as well. I'm looking for inspiration in other projects, but it seems all of them have an open ticket for that, it's really no easy achievement...
It's for this project: https://github.com/rsalmei/alive-progress
alive-progress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants