I try to implement a nested progress bar, which resets the inner.
The following works for displaying the progress as I expected:
import time
from rich.progress import Progress
with Progress() as progress:
task1 = progress.add_task("[red]Downloading...", total=2)
task2 = progress.add_task("[green]Processing...", total=2)
task3 = progress.add_task("[cyan]Cooking...", total=200)
for i in range(2):
progress.update(task2, completed=0)
for j in range(2):
progress.update(task3, completed=0)
for k in range(200):
progress.update(task3, advance=1)
time.sleep(0.01)
else:
progress.update(task2, advance=1)
else:
progress.update(task1, advance=1)
The result looks like this:
Downloading... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Processing... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Cooking... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
What I am irritated by is the time. While for task3
the timer ticks down in the first loop, the timer for task1
and task2
starts with -:--:--
which I expected, but in the second iteration displays 0:00:00
instead of the cumulative time of the lower loops.
Additionally, the time will stick at 0:00:00
after running ones.
I've tested a bit further and realized, that if I increase the total of task1
and taks2
. It seems to be that at least calculate their estimated time, but also sticks at 0:00:00
after the first loop.
Do I need to reset the timer the same way I reset the completed
count?