Skip to content

Progress bar should advance at end of loop #651

Closed

Description

@jdno

I'm using the progress bar with a piece of code like this:

with click.progressbar(some_list) as bar:
    for element in bar:
        element.long_calculation

It seems that the progress bar updates every time it enters the loop, which for the last element means the bar shows everything has been completed, although the last computation just started. It would be great if it would show the progress in terms of results, not as an iterator.

I looked briefly at the implementation in _termui_impl.py, but the rendering seems to be closely linked to the pos attribute and I don't feel comfortable to mess with that. 😒

Activity

  1. untitaker commented on Sep 6, 2016

    @untitaker
    Contributor

    This just seems like a off-by-one error to me.

  2. jdno commented on Sep 6, 2016

    @jdno
    Author

    Might be. The ETA is definitely off by one.

    Here is the small script I used to test this:

    import time
    
    import click
    
    @click.command()
    @click.option('--count', default=1)
    def test(count):
        with click.progressbar(range(count)) as bar:
            for x in bar:
                time.sleep(2)
    
    if __name__ == '__main__':
        test()
  3. added a commit that references this issue on May 14, 2018
    21d5125
  4. added this to the 7.0 milestone on Sep 10, 2018
  5. added 2 commits that reference this issue on Oct 8, 2018
  6. added a commit that references this issue on Oct 29, 2018
  7. locked as resolved and limited conversation to collaborators on Nov 13, 2020
  8. added
    help output
    on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help output

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions