[BUG]Repeated display of completed progress bars
- [x] I've checked docs and closed issues for possible solutions.
- [x] I can't find my issue in the FAQ.
Describe the bug My code is to loop through the input and display the download file progress bar. If there were previously completed progress bars, the latest progress bar will repeatedly display those completed progress bars
The example code is as follows
progress = Progress(
TextColumn(
"[progress.description]{task.description}",
justify="left"),
"•",
BarColumn(
bar_width=20),
"[progress.percentage]{task.percentage:>3.1f}%",
"•",
DownloadColumn(
binary_units=True),
"•",
TimeRemainingColumn(),
)
while True:
text = input("Input Content")
with progress:
task_id = progress.add_task(
text, start=False, total=None)
progress.update(task_id, total=10)
progress.start_task(task_id)
with open("demo.txt", "wb") as f:
for chunk in response.iter_content(chunk_size=self.chunk):
f.write(chunk)
progress.update(task_id, advance=len(chunk))
Sample screenshot
In the picture, the progress bar at the end of 29373 is the first and completed progress bar, while the progress bar at the end of 39781 is the second one. It is running but carries the progress bar that was completed in the first time. If there is a third progress bar, it will also carry the progress bar that was completed in the first two times
Other information
╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface. │
│ │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=160 ColorSystem.TRUECOLOR> │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ color_system = 'truecolor' │
│ encoding = 'utf-8' │
│ file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│ height = 30 │
│ is_alt_screen = False │
│ is_dumb_terminal = False │
│ is_interactive = True │
│ is_jupyter = False │
│ is_terminal = True │
│ legacy_windows = False │
│ no_color = False │
│ options = ConsoleOptions( │
│ size=ConsoleDimensions(width=160, height=30), │
│ legacy_windows=False, │
│ min_width=1, │
│ max_width=160, │
│ is_terminal=True, │
│ encoding='utf-8', │
│ max_height=30, │
│ justify=None, │
│ overflow=None, │
│ no_wrap=False, │
│ highlight=None, │
│ markup=None, │
│ height=None │
│ ) │
│ quiet = False │
│ record = False │
│ safe_box = True │
│ size = ConsoleDimensions(width=160, height=30) │
│ soft_wrap = False │
│ stderr = False │
│ style = None │
│ tab_size = 8 │
│ width = 160 │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭── <class 'rich._windows.WindowsConsoleFeatures'> ───╮
│ Windows features available. │
│ │
│ ╭─────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=True, truecolor=True) │ │
│ ╰─────────────────────────────────────────────────╯ │
│ │
│ truecolor = True │
│ vt = True │
╰─────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ { │
│ 'TERM': None, │
│ 'COLORTERM': None, │
│ 'CLICOLOR': None, │
│ 'NO_COLOR': None, │
│ 'TERM_PROGRAM': None, │
│ 'COLUMNS': None, │
│ 'LINES': None, │
│ 'JUPYTER_COLUMNS': None, │
│ 'JUPYTER_LINES': None, │
│ 'JPY_PARENT_PID': None, │
│ 'VSCODE_VERBOSE_LOGGING': None │
│ } │
╰────────────────────────────────────╯
platform="Windows"
Thank you for your issue. Give us a little time to review it.
PS. You might want to check the FAQ if you haven't done so already.
This is an automated reply, generated by FAQtory
This is a minimum reproducible example (MRE)
from rich.console import Console
from rich.progress import (
Progress,
TextColumn,
BarColumn,
DownloadColumn,
TimeRemainingColumn,
)
import time
console = Console()
progress = Progress(
TextColumn(
"[progress.description]{task.description}",
justify="left"),
"•",
BarColumn(
bar_width=20),
"[progress.percentage]{task.percentage:>3.1f}%",
"•",
DownloadColumn(
binary_units=True),
"•",
TimeRemainingColumn(),
console=console,
)
for i in range(1, 5):
text = input("Input Content")
with progress:
task_id = progress.add_task(
f"task {i}", start=False, total=None)
progress.update(task_id, total=10)
progress.start_task(task_id)
for chunk in range(10):
time.sleep(0.2)
progress.update(task_id, advance=chunk)
It even ate my input prompt
In case you don't need all the progress bars to stay together, consider creating a new progress bar at the start of each loop instead of adding all the tasks to the same progress bar. That should fix it.
Using a new Progress object every time can indeed solve the problem of duplicate progress bars. Thank you.