Debian Codegraph @

examples/jobs.py

raw
1 from time import sleep
2 from rich.panel import Panel
3 from rich.progress import Progress
4
5
6 JOBS = [100, 150, 25, 70, 110, 90]
7
8 progress = Progress(auto_refresh=False)
9 master_task = progress.add_task("overall", total=sum(JOBS))
10 jobs_task = progress.add_task("jobs")
11
12 progress.console.print(
13 Panel(
14 "[bold blue]A demonstration of progress with a current task and overall progress.",
15 padding=1,
16 )
17 )
18
19 with progress:
20 for job_no, job in enumerate(JOBS):
21 progress.log(f"Starting job #{job_no}")
22 sleep(0.2)
23 progress.reset(jobs_task, total=job, description=f"job [bold yellow]#{job_no}")
24 progress.start_task(jobs_task)
25 for wait in progress.track(range(job), task_id=jobs_task):
26 sleep(0.01)
27 progress.advance(master_task, job)
28 progress.log(f"Job #{job_no} is complete")
29 progress.log(
30 Panel(":sparkle: All done! :sparkle:", border_style="green", padding=1)
31 )