question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TQDM progress bar

See original GitHub issue

Description of your problem

The nested-loop function of the TQDM progress bar does not behave as it should.

When you run the TQDM progress bar module in Spyder, running a single loop produces the correct ouput behavior: the progress bar remains on a single line and updates itself. For instance,

from tqdm import trange
from time import sleep

for i in trange(100, desc='Single loop'):
    sleep(0.01)

Produces a single line which updates itself nicely then returns you to the console

Single loop: 50%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ | 50/100 [00:00<00:00, 98.52it/s]

However, if you try to use nested loops, TQDM is no longer able to update the two lines without adding newlines, resulting in spammed whitespace. For instance:

from tqdm import trange
from time import sleep

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

Will produce a console filled with extra whitespace and each new progress update will take up a newline like so:

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

3nd loop:   0%|          | 0/100 [00:00<?, ?it/s]

3nd loop:  10%|β–ˆ         | 10/100 [00:00<00:00, 97.94it/s]

3nd loop:  20%|β–ˆβ–ˆ        | 20/100 [00:00<00:00, 96.52it/s]

3nd loop:  30%|β–ˆβ–ˆβ–ˆ       | 30/100 [00:00<00:00, 96.06it/s]

3nd loop:  40%|β–ˆβ–ˆβ–ˆβ–ˆ      | 40/100 [00:00<00:00, 96.06it/s]

3nd loop:  50%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ     | 50/100 [00:00<00:00, 96.06it/s]

3nd loop:  60%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ    | 60/100 [00:00<00:00, 96.21it/s]

3nd loop:  70%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   | 70/100 [00:00<00:00, 96.19it/s]

3nd loop:  80%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  | 80/100 [00:00<00:00, 96.06it/s]

However, in the regular IPython console started from the command line, this behaves as expected, with each line remaining in place and being updated in-place.

1st loop:  10%|β–ˆ         | 1/10 [00:05<00:47,  5.33s/it]
2nd loop:  20%|β–ˆβ–ˆ        | 1/5 [00:01<00:04,  1.06s/it]
3nd loop:  70%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   | 70/100 [00:00<00:00, 95.53it/s]

I have tried installing colorama as suggested in this TQDM issue here, but the issue remains. It is also consistent across Windows and OS X versions of Spyder.

In both OS X and Windows, the TQDM behavior works as desired if I input it directly into a command-line python console (or IPython console), but produces the spammy behavior if I run it in the Spdyer console window.

I’m not familiar with the console system, but I believe this may have something to do with β€œup” character not being respected as it’s passed from the ipython console to the spyder console, and so the upper line cannot be updated and instead. But that’s just a guess

Versions and main components

  • Spyder Version: 3.2.5
  • Python Version: 3.6.3
  • Qt Version: 5.6.2
  • PyQt Version: 5.6
  • Operating system: Windows (also tested on OS X with same setup)

Dependencies

IPython >=4.0 : 6.1.0 (OK) cython >=0.21 : 0.26.1 (OK) jedi >=0.9.0 : 0.10.2 (OK) nbconvert >=4.0 : 5.3.1 (OK) numpy >=1.7 : 1.13.3 (OK) pandas >=0.13.1 : 0.20.3 (OK) pycodestyle >=2.3: 2.3.1 (OK) pyflakes >=0.6.0 : 1.6.0 (OK) pygments >=2.0 : 2.2.0 (OK) pylint >=0.25 : 1.7.4 (OK) qtconsole >=4.2.0: 4.3.1 (OK) rope >=0.9.4 : 0.10.5 (OK) sphinx >=0.6.6 : 1.6.3 (OK) sympy >=0.7.3 : 1.1.1 (OK)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
dalthvizcommented, Nov 18, 2020

Hi @seyeeet yep this has not been fix but hopefully a fix will be part of Spyder 4.2.1

1reaction
ccordoba12commented, Oct 16, 2020

I thought they were fixed. We’ll take a look at this after we release 4.2.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

tqdm/tqdm: A Fast, Extensible Progress Bar for Python and CLI
This is a work in progress (see #737). Since tqdm uses a simple printing mechanism to display progress bars, you should not write...
Read more >
Python | How to make a terminal progress bar using tqdm
You can use the Python external library tqdm, to create simple & hassle-free progress bars which you can add to your code and...
Read more >
How to Use Progress Bars in Python? | tqdm and tqdm Notebook
tqdm is a library in Python which is used for creating Progress Meters or Progress Bars. In this article learn how to create...
Read more >
tqdm documentation
tqdm means "progress" in Arabic (taqadum, ΨͺΩ‚Ψ―Ω‘Ω…) and is an abbreviation for ... By comparison, the well-established ProgressBar has an 800ns/iter overhead.
Read more >
How to create a Python terminal progress bar using tqdm?
tqdm is a Python library that provides functions that wrap around the specified iterable to give a smart progress bar as an output....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found