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.

Progressbar do not advance with `.next()` call

See original GitHub issue

Expected Behavior

with the following code:

import time
import click

lst = list(range(10))
with click.progressbar(lst) as bar:
    for i in lst:
        next(bar)
        time.sleep(0.2)

bar just don’t advance, related to https://github.com/pallets/click/issues/1125.

Actual Behavior

works fine with click-6.7.

Environment

  • Python version: 3.8.2 on macOS
  • Click version: 7.1.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
obfuskcommented, Jun 4, 2020

I don’t think this is a bug in click. You’re calling next() on something that may not be an iterator.

I’m also not sure why you’re iterating over lst instead of bar. The following works fine:

import time
import click

lst = list(range(10))
with click.progressbar(lst) as bar:
    for i in bar:
        time.sleep(0.2)

If, for some reason, you really want to iterate over lst instead of bar, you can call next() on an iterator over bar (obtained using iter()):

import time
import click

lst = list(range(10))
with click.progressbar(lst) as bar:
    it = iter(bar)
    for i in lst:
        next(it)
        time.sleep(0.2)
1reaction
obfuskcommented, Jun 5, 2020

@obfusk besides, with your code, the progress bar will not reach 100%:

You got me there. It’s missing the final step. This does work:

import time
import click

lst = list(range(10))
with click.progressbar(lst) as bar:
    it = iter(bar)
    for i in lst:
        next(it)
        time.sleep(0.2)
    next(it, None)

But the first example I gave of just iterating over bar in the for loop – and not calling next() manually – works just fine and is the intended use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

android progressBar does not update progress view/drawable
SOLUTION: It's a Bug in ProgressBar! finally... I think I found the solution... this does not work as one would expect: bar.setMax(50); bar....
Read more >
How to build a progress bar indicator in Next.js - LogRocket Blog
This tutorial will address this issue by demonstrating how to build and display a progress bar indicator when changing routes in a Next.js ......
Read more >
Progress Bars - Electron
A progress bar enables a window to provide progress information to the user without the need of switching to the window itself. On...
Read more >
A Complete Guide to Using Python Progress Bars - Built In
A progress bar in Python indicates whether the code is working or stuck in a loop due to an error. Here's how to...
Read more >
Progress Bar — Cleo 0.6.1 documentation
Whenever your task is finished, don't forget to call finish() to ensure that the progress bar display is refreshed with a 100% completion....
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