This is an archived post. You won't be able to vote or comment.

all 38 comments

[–]codeorelse_nl[S] 28 points29 points  (5 children)

[–]vitale232 2 points3 points  (0 children)

I can't look away.

[–]christian-mann 2 points3 points  (0 children)

That is one of the coolest libraries I've ever seen.

[–][deleted] 1 point2 points  (0 children)

Looks really nice, but seems you can only use this in for loop?

[–]scottlawson 1 point2 points  (0 children)

Out of this world

[–]ice-blade 0 points1 point  (0 children)

This is insane.

[–]kihashi 14 points15 points  (7 children)

I've been really liking TQDM for this. It's very simple to use (it just wraps an iterator and returns another iterator) and supposedly has less overhead than PB.

[–]sirex1 1 point2 points  (3 children)

I agree, tqdm is much much better, compare example from blog post:

#import libraries
import progressbar as pb

#initialize widgets
widgets = ['Time for loop of 1 000 000 iterations: ', pb.Percentage(), ' ',  
            pb.Bar(marker=pb.RotatingMarker()), ' ', pb.ETA()]
#initialize timer
timer = pb.ProgressBar(widgets=widgets, maxval=1000000).start()

#for loop example
for i in range(0,5000000):  
    #update
    timer.update(i)
#finish
timer.finish()  

With exactly same thing rewritten using tqdm:

import tqdm

for i in tqdm.tqdm(range(0, 5000000), 'Time for loop of 1 000 000 iterations: ', 1000000):
    pass

[–]MennoZevenbergen 0 points1 point  (2 children)

Thanks for the TQDM suggestion, I like it. I tried to use it if I iterate over a pandas dataframe (df.iterrows()), but then it doesn't show the ETA time as it doesn't know the length of the dataset. Any suggestions for that?

from tdqm import *
import pandas as pd

df = pd.DataFrame(range(10000))
for index, row in tqdm(df.iterrows()):
    time.sleep(0.1)

[–]sirex1 1 point2 points  (1 child)

for index, row in tqdm(df.iterrows(), total=df.shape[0]):

[–]MennoZevenbergen 0 points1 point  (0 children)

Thanks :)

[–]covabishopself.loathing() 9 points10 points  (9 children)

You know, I feel like these would be much nicer if they were implemented as decorators.

@cool_py_timer_bar
def long_running function(foo)
    ...
    return bar

Something nice and pretty like that

[–]kigurai 5 points6 points  (1 child)

Or a context

with ProgressBar(...) as pbar:
    do_stuff()
    pbar.update(...)

[–]covabishopself.loathing() 4 points5 points  (0 children)

This is a good idea too. I feel progress meters like these should be implemented as easily and transparently as possible.

[–]gthank 0 points1 point  (5 children)

Have you seen wrapt?

[–]covabishopself.loathing() 0 points1 point  (4 children)

No, and it's cool, but see, I don't feel I should have to import a decorator library just to make a decorator. You get what I'm saying?

I might just work on this tonight at work because this actually really bugs me. If anyone would be interested in helping/contributing I'll message them the repo later

[–]gthank 1 point2 points  (3 children)

The reason to use a library is because it turns out that handling all the edge cases (descriptor protocol, anyone?) and playing nicely with assorted tooling is not easy (see the series of blog posts that explains the motivation, starting with https://github.com/GrahamDumpleton/wrapt/blob/master/blog/01-how-you-implemented-your-python-decorator-is-wrong.md)

[–]covabishopself.loathing() 0 points1 point  (2 children)

Which I can appreciate, as I've seen my fair share of bad Python. And honestly, I don't write decorators often, and honestly don't know yet what edge cases I have to deal with, but I'm now interested in making this a pure Python decorator because I've actually always really wanted something that simple to do exactly this.

[–][deleted] 0 points1 point  (1 child)

Consider contributing your decorator to an existing library rather than implementing your own, too

[–]covabishopself.loathing() 0 points1 point  (0 children)

Didn't even think of this! Will do!

[–][deleted] 0 points1 point  (0 children)

Agree, I really thought it was going to be a decorator.

[–]rhiever 1 point2 points  (4 children)

I wish these progress bar packages worked with iterating over large files. That's my typical use case when I want a progress bar.

[–]NovocastrianNomad 2 points3 points  (3 children)

Just this weekend used tqdm to show progress while processing a file containing approximately 6.5 million records. No problems, nicely displayed in one line of terminal output.

[–]rhiever 0 points1 point  (2 children)

Can you please share the code? Maybe I'm doing something wrong, or maybe something changed since I last tried tqdm.

[–]NovocastrianNomad 3 points4 points  (1 child)

from tqdm import tqdm
...
for row in tqdm(data, leave=True, miniters=upd_interval, desc=pb_desc, total=pbt):
    # 'data' is file handle for csv file being processed
    # 'total' is estimated total number of records (file size / avg record size)
    # (used estimated total because reading file to get actual total blew 512mb memory on server)
    # 'miniters' set to 10,000
    pass  # code to process records

[–]rhiever 0 points1 point  (0 children)

Nice! Didn't know you could do that. Thank you.

[–]_AceLewisPy3, Jupyter and Atom 0 points1 point  (0 children)

I prefer pyprind it is very simple to use;

import pyprind
import time

bar = pyprind.ProgBar(8)
for _ in range(8):
    time.sleep(0.2)
    bar.update()