-
-
Notifications
You must be signed in to change notification settings - Fork 102
Open
Labels
Description
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()):
passASCIInema 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