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

Nested Trees? #384

Closed
dstufft opened this issue May 20, 2017 · 4 comments
Closed

Nested Trees? #384

dstufft opened this issue May 20, 2017 · 4 comments

Comments

@dstufft
Copy link

dstufft commented May 20, 2017

I see how to handle nested progress bars, but I wonder if it's possible to have nested trees? If not is that something you could see yourself adding? This is sort of like what was asked in #312 except you want the ability to have multiple progress bars going at once.

You can see an example of this at https://github.com/hfaran/progressive/.

@casperdcl
Copy link
Sponsor Member

casperdcl commented May 21, 2017

you could make things tree-like...

from tqdm import trange
from time import sleep


for i in trange(9, desc=' '):
    for j in trange(i, desc=' ' * 5):
        for k in trange(j, desc=' ' * 9):
            sleep(0.1)
print('\n')
 : 100%|█████████████████████████████| 9/9 [00:08<00:00,  1.69s/it]
     : 100%|█████████████████████████| 8/8 [00:02<00:00,  2.03it/s]
         : 100%|█████████████████████| 7/7 [00:00<00:00,  9.95it/s]

@dstufft
Copy link
Author

dstufft commented May 21, 2017

If I'm not mistaken, while that displays as a tree, it only really allows you to advance the inner most progress bar doesn't it? One of the goals here is to have the inner most bars operate entirely independently of each other and they can be progressing in parallel (in say worker threads or something).

@casperdcl
Copy link
Sponsor Member

casperdcl commented May 22, 2017

See #329, #285... Not tested and haven't added multithreading here but you get the idea:

from tqdm import tqdm, trange
from time import sleep

a1 = tqdm(total=2, desc="a1", position=0)
b1 = tqdm(total=2, desc="  b1", position=1)
c1 = trange(9, desc="    c1", position=2)
c2 = trange(9, desc="    c2", position=3)
b2 = trange(9, desc="  b2", position=4)

def do(inner, outer):
    for i in inner:
        sleep(0.1)
    outer.update()

def do_b1():
    do(c1, b1)
    do(c2, b1)
    a1.update()

def do_b2():
    for i in b2:
        sleep(0.1)
    a1.update()

def do_a1():
    do_b1()
    do_b2()

do_a1()
print('\n' * 3)
a1: 100%|█████████████████████████████████████████| 2/2 [00:02<00:00,  1.54s/it]
  b1: 100%|███████████████████████████████████████| 2/2 [00:01<00:00,  1.10it/s]
    c1: 100%|█████████████████████████████████████| 9/9 [00:00<00:00,  9.96it/s]
    c2: 100%|█████████████████████████████████████| 9/9 [00:01<00:00,  6.55it/s]
  b2: 100%|███████████████████████████████████████| 9/9 [00:02<00:00,  4.88it/s]

Note you might need #385 to get this working properly. Writing this minimal example definitely helped me find this bug. Thanks @dstufft. @lrq3000 please review #385 as I think it may fix a few related issues, but possibly cause some too.

@casperdcl
Copy link
Sponsor Member

closing as assumed solved. Happy to re-open if there are any more suggestions.

casperdcl added a commit that referenced this issue Sep 26, 2017
fixes #285 -> #291 -> #329
fixes #422
fixes #439

fixes #323
fixes #324
fixes #334
fixes #407
fixes #418

related to:
- #97
- #143
- #331
- #361
- #384
- #385
- #417
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

2 participants