最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - rich.Progress nested with correct time - Stack Overflow

programmeradmin2浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论