pyprind
pyprind copied to clipboard
Using double progressbars?
Hi. Thx for this package. I've one question: How can i use 2 progressbars at same time? One for main loop, second for subloop? For example file copy utility (like in FAR): 1 progressbar shows how many files ramained 2 progressbar shows file copy progress
I've tryed to simply add second bar inside first bar loop
n = 10
items = ['file_%s.csv' %i for i in range(1,10)]
bar = pyprind.ProgBar(len(items))
for i in items:
bar.update(item_id = i)
for z in pyprind.prog_percent(range(n), monitor=True):
time.sleep(0.1) # do some computation
print bar
here is output
0% 100%
[100 %] elapsed[sec]: 1.099 | ETA[sec]: 0.000
Total time elapsed: 1.099 sec
[100 %] elapsed[sec]: 1.095 | ETA[sec]: 0.000 2.csv
Total time elapsed: 1.095 sec
[100 %] elapsed[sec]: 1.099 | ETA[sec]: 0.000 3.csv
Total time elapsed: 1.099 sec
[100 %] elapsed[sec]: 1.099 | ETA[sec]: 0.000 4.csv
Total time elapsed: 1.099 sec
[100 %] elapsed[sec]: 1.102 | ETA[sec]: 0.000 5.csv
Total time elapsed: 1.102 sec
[100 %] elapsed[sec]: 1.100 | ETA[sec]: 0.000 6.csv
Total time elapsed: 1.100 sec
[100 %] elapsed[sec]: 1.105 | ETA[sec]: 0.000 7.csv
Total time elapsed: 1.105 sec
[100 %] elapsed[sec]: 1.100 | ETA[sec]: 0.000 8.csv
Total time elapsed: 1.100 sec
[#########] | ETA[sec]: 0.000 | Item ID: file_9.csv
Total time elapsed: 8.799 sec
[100 %] elapsed[sec]: 1.086 | ETA[sec]: 0.000
Total time elapsed: 1.086 sec
Title:
Started: 12/13/2015 00:20:42
Finished: 12/13/2015 00:20:51
Total time elapsed: 8.799 sec
this is not what i exspected to see :)
Hi, amirotin! Unfortunately, the current implementation only supports one progress bar/ progress percent tracker at a time. I think that having nested progress bars would be a super useful feature. However, I am currently not sure how to implement it (it would require that you could jump between multiple lines in the output stream. But I will leave this issue open, and I will brainstorm a bit.
Hi rasbt, could this potentially be implemented using the curses library? It allows you to manipulate the cursor position with greater control than how you're currently doing it. I believe this would also allow the users to print to stdout while looping without duplicating the progress indicator.
@BrandonHeinrich Sorry for getting back to you so late, I'd been on vacation in December, and somehow the note must still be buried in some email inbox
Anyway, I honestly haven't heard of the curses
library before; didn't know that such a neat package would be in the stdlib. I think it would be great to substitute the current way of printing the progress bar using curses
. This may then also make the "double progressbars" possible!
I am not sure when I'd be able to get to that, but if you (or someone else) wants to contribute, I'd be very happy about this addition! :)
This anwser maybe help,https://stackoverflow.com/questions/6840420/python-rewrite-multiple-lines-in-the-console
Thanks! I remember looking at the curses library some time ago. I think the reason why I ended up not using it for PyPrind was that it's OS specific. Personally, I am only using macOS and Linux, but I think a large portion of Python users in general are using Windows, which doesn't support curses afaik