Skip to content

nested or positioned bars are broken #1139

Closed

Description

@mgdelmonte
  • I have marked all applicable categories:
    • visual output bug
  • I have visited the [source website], and in particular read the [known issues]
  • I have searched through the [issue tracker] for duplicates
  • I have mentioned version numbers, operating system and environment, where applicable

Versions:

Windows 10
tqdm 4.59.0
sys.version 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)]
sys.platform win32

Mac OS Catalina 10.15.6
tqdm 4.59.0
sys.version 3.9.2
sys.platform darwin

Nested or positioned bars are not working. Visual output is either a series of scrolling bars, or bars that jump around. The current "nested bars" example at https://github.com/tqdm/tqdm#nested-progress-bars

from tqdm.auto import trange
from time import sleep

for i in trange(4, desc='1st loop'):
    for j in trange(5, desc='2nd loop'):
        for k in trange(50, desc='3rd loop', leave=False):
            sleep(0.01)

generates this on Windows:

C:\Users\Michael\Downloads>python test.py
1st loop:   0%|                                                                  | 0/4 [00:00<?, ?it/s]
2nd loop:   0%|                                                                  | 0/5 [00:00<?, ?it/s]

3rd loop:   0%|                                                                 | 0/50 [00:00<?, ?it/s]

3rd loop:  14%|███████▉                                                 | 7/50 [00:00<00:00, 68.50it/s]

3rd loop:  28%|███████████████▋                                        | 14/50 [00:00<00:00, 65.75it/s]

3rd loop:  42%|███████████████████████▌                                | 21/50 [00:00<00:00, 65.05it/s]

3rd loop:  56%|███████████████████████████████▎                        | 28/50 [00:00<00:00, 64.88it/s]

2nd loop:   0%|                                                                  | 0/5 [00:00<?, ?it/s]
1st loop:   0%|                                                                  | 0/4 [00:00<?, ?it/s]

On Mac, it generates bars that mostly work but which scroll down whenever loop2 completes, leaving a display that shows

2nd loop: 100%|███████████| 5/5 [00:03<00:00,  1.66it/s]
2nd loop: 100%|███████████| 5/5 [00:03<00:00,  1.66it/s]
2nd loop: 100%|███████████| 5/5 [00:03<00:00,  1.66it/s]
2nd loop: 100%|███████████| 5/5 [00:03<00:00,  1.66it/s]
1st loop: 100%|███████████| 4/4 [00:12<00:00,  3.03it/s]

Further testing shows that other examples using position, including both threading and multiprocessing examples, all produce broken output on both Windows and Mac.

Activity

  1. filak commented on Mar 9, 2021

    @filak

    In tqdm version 4.55.1 the final result is the same as in the Mac example.

    With a simple test:

        from tqdm import tqdm
        from time import sleep
        
        p = 1 # 0
        data = range(20)
        
        print('Position', p)
        for item in tqdm( data, ascii=True, position=p):
            sleep(0.01)
    

    v4.55.1

     Position 0
     100%|###################### ... | 20/20 [00:00<00:00, 63.70it/s]
    

    Pos 1:

     Position 1
     100%|###################### ... | 20/20 [00:00<00:00, 63.70it/s]
     70%|################3           | 14/20 [00:00<00:00, 63.62it/s]
    

    v4.59.0

     Position 0
     100%|###################### ... | 20/20 [00:00<00:00, 63.70it/s]
    

    Pos 1:

     Position 1
    
     0%|                             | 0/20 [00:00<?, ?it/s]
     100%|###################### ... | 20/20 [00:00<00:00, 92.42it/s]
    
  2. AlexanderStein commented on Mar 26, 2021

    @AlexanderStein

    2nd loop: 100%|███████████| 5/5 [00:03<00:00, 1.66it/s]
    2nd loop: 100%|███████████| 5/5 [00:03<00:00, 1.66it/s]
    2nd loop: 100%|███████████| 5/5 [00:03<00:00, 1.66it/s]
    2nd loop: 100%|███████████| 5/5 [00:03<00:00, 1.66it/s]
    1st loop: 100%|███████████| 4/4 [00:12<00:00, 3.03it/s]

    I get this kind of output on my Windows machine as well on Linux connected using PuTTY. Both for v4.55.1 and v4.59.0.

    So I tried several released on Windows and Linux and found that starting with v4.34.0 this odd behaviour starts. v4.33.0 is still ok.

    From the release notes #795 as well as #230 are in regard of nested bars.
    I found that using the following test code works even on v4.59.0:

    from tqdm.auto import trange
    from time import sleep
    
    for i in trange(4, desc='1st loop'):
        for j in trange(5, desc='2nd loop', leave=False):
            for k in trange(50, desc='3rd loop', leave=False):
                sleep(0.01)
    

    Notice the leave=False in the second loop. Everything works as intended, on Windows and Linux. So it appears to be something around that leave parameter.

  3. mgdelmonte commented on May 29, 2021

    @mgdelmonte
    Author

    Just confirming that this issue still exists, and the behavior is the same in v4.60.0 and v4.61.0

  4. Macil commented on May 30, 2021

    @Macil

    I had this same issue, and I finally fixed it by running pip install colorama. Turns out the readme has a hint about this: "Windows: additionally may require the Python module colorama to ensure nested bars stay within their respective lines.".

    Is there a reason colorama isn't a required dependency so it would be installed automatically? It was really frustrating for me to figure this out since it took me an hour to even figure out this issue had to do with tqdm (I was using a project, big-sleep, that has a dependency on something that itself has a dependency on tqdm) so I spent a lot of time investigating before even figuring out to look at tqdm's readme.

  5. self-assigned this
    on Jun 12, 2021
  6. added this to the Non-breaking milestone on Jun 12, 2021
  7. added a commit that references this issue on Jun 12, 2021
    9f4ae74
  8. aboutyy commented on Aug 3, 2021

    @aboutyy

    2nd loop: 100%|███████████| 5/5 [00:03<00:00, 1.66it/s]
    2nd loop: 100%|███████████| 5/5 [00:03<00:00, 1.66it/s]
    2nd loop: 100%|███████████| 5/5 [00:03<00:00, 1.66it/s]
    2nd loop: 100%|███████████| 5/5 [00:03<00:00, 1.66it/s]
    1st loop: 100%|███████████| 4/4 [00:12<00:00, 3.03it/s]

    I get this kind of output on my Windows machine as well on Linux connected using PuTTY. Both for v4.55.1 and v4.59.0.

    So I tried several released on Windows and Linux and found that starting with v4.34.0 this odd behaviour starts. v4.33.0 is still ok.

    From the release notes #795 as well as #230 are in regard of nested bars.
    I found that using the following test code works even on v4.59.0:

    from tqdm.auto import trange
    from time import sleep
    
    for i in trange(4, desc='1st loop'):
        for j in trange(5, desc='2nd loop', leave=False):
            for k in trange(50, desc='3rd loop', leave=False):
                sleep(0.01)
    

    Notice the leave=False in the second loop. Everything works as intended, on Windows and Linux. So it appears to be something around that leave parameter.

    This worked in the command line not in Pycharm console

  9. casperdcl commented on Aug 3, 2021

    @casperdcl
    SponsorMember

    @aboutyy yes that's expected & intended behaviour.

    Regarding PyCharm, lack of nested support is a known issue

  10. aboutyy commented on Aug 4, 2021

    @aboutyy

    @aboutyy yes that's expected & intended behaviour.

    Regarding PyCharm, lack of nested support is a known issue

    Any way to fix it?

  11. cynical-guy commented on Dec 2, 2021

    @cynical-guy

    I have the same issue:
    Fedora 35 - 5.14.18-300.fc35.x86_64
    Python 3.10.0
    tqdm 4.62.3

    I confirm, that according to my test, this issue goes away if I switch to tqdm 4.33.0, and reoccurs if I upgrade to 4.34.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions