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

Progress bar is duplicated when used both as a context manager and as an iterable wrapper #301

Open
dreamscached opened this issue Sep 22, 2024 · 3 comments

Comments

@dreamscached
Copy link

Description

When used both as context manager (e.g. with) and as iterable wrapper, exhausting the iterable and exiting the with scope causes the progress bar to duplicate.

Code

Consider the following example code:

from time import sleep
from progressbar import ProgressBar
from progressbar.widgets import AnimatedMarker, SimpleProgress, GranularBar, Timer

def simple_iterator():
    for i in range(100):
        sleep(0.02)
        yield i

progress = ProgressBar(
    max_value=100,
    redirect_stdout=True,
    redirect_stderr=True,
    widgets=[AnimatedMarker("⡏⠟⠻⢹⣸⣴⣦⣇"), " ",
             SimpleProgress(), " ",
             GranularBar(markers="░▒▓█"), " ",
             Timer()]
)

with progress:
    for i in progress(simple_iterator()):
        pass

ASCIInema demo: https://asciinema.org/a/UEEc81s5GyrAR3QaqLDWGIMGX

Versions

  • Python version: 3.12.6 (main, Sep 8 2024, 13:18:56) [GCC 14.2.1 20240805]
  • Python distribution/environment: CPython
  • Operating System: Arch Linux, etc.
  • Package version: 4.5.0
@dreamscached
Copy link
Author

I assume finish is invoked twice for some reason, because leaving in either a context manager only or iterable wrapper only, it works as expected.

@github-actions github-actions bot added the Stale label Oct 23, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2024
@dreamscached
Copy link
Author

Bumping because it's still an issue and was not solved.

@wolph wolph reopened this Oct 30, 2024
@wolph
Copy link
Owner

wolph commented Oct 30, 2024

Bumping because it's still an issue and was not solved.

Sorry about he inactivity, I've seen the issue but I've had very little time.

It's definitely a bug :)

@wolph wolph added in-progress and removed Stale labels Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants