rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.53k stars 206 forks source link

Bar in recursive function #197

Closed Simooo45 closed 2 years ago

Simooo45 commented 2 years ago

Hi @rsalmei, I've seen your beautiful work, I tried to use in a recoursive function (I tried to create the alive-bar object before the recursion and used that as a parameter of the function) and that raised Exception. There is something that I can do in order to avoid it? Thank you soo much, best wishes.

TheTechRobo commented 2 years ago

What exception? Provide the stack trace or we can't help you

Simooo45 commented 2 years ago

TypeError: ContextDecorator.__call__() missing 1 required positional argument: 'func'

The function is used to read a tree structure: if a node doesn't have children calls bar(). The structure is like:

def parse_tree(tree, bar=None):
     result = []
     if has_children(tree):
          for child in tree:
               result += parse_tree(child, bar=bar)
     else:
          result = ...
          bar()
     return result

bar = alive_bar(0, title="Main")
x = parse_tree(tree, bar=bar)

probably I'm just making a dumb blunder, but maybe you can help me :).

Thank you!

Simooo45 commented 2 years ago

In fact was a dumb blunder... I tried the same thing, but with

with alive_bar(0, title="Main") as bar:
     x = parse_tree(tree, bar=bar)

and that works. Thank you for your help and your library!

rsalmei commented 2 years ago

Thanks @Simooo45! I'm glad you worked that out 👍