Skip to main content

Simple to use progress bar with subprocesses and threads.

Project description

MultiProgress: the enriched progress bar

A simple to use progress_bar in sub-processes or threads using rich. See the examples folder for more examples.

import time
import random
from concurrent.futures import ProcessPoolExecutor
from enriched_progress import MultiProgress, progress_bar


def do_work(n: int) -> int:
    sleep_for = random.randint(0, 2)
    for _ in progress_bar(
        range(1, n + 2), desc=f"Sleeping for {sleep_for} secs for each {n} iterations."
    ):
        time.sleep(sleep_for)
    return sleep_for


def demo():
    with ProcessPoolExecutor() as p, MultiProgress():
        print(list(p.map(do_work, range(10))))

Install

pip install multiprog

Using Other Rich Features

[!Note] The progress_bar function doesn't need to know about the MultiProgress instance. The only time the two components will need to share state is the case where multiple instances of MultiProgress are being used in the main process. In such cases you will use a key to send progress updates to the correct instance.

import time
from rich.console import Console, Group
from rich.live import Live
from rich.panel import Panel
from concurrent.futures import ProcessPoolExecutor, as_completed
from enriched_progress import MultiProgress, progress_bar
import random
import os


def work(status_name: str) -> str:
    for _ in progress_bar(
        range(random.randint(2, 40)),
        desc=f"Working on task for {status_name}",
        metrics_func=lambda: dict(pid=os.getpid()),
    ):
        time.sleep(random.random() * 2)
    return status_name


def demo():
    console = Console()
    status = console.status("Working on tasks...")
    with (
        ProcessPoolExecutor() as p,
        MultiProgress(transient=True)(live_mode=False) as mp,
        Live(Panel(Group(status, mp))),
    ):
        futures = [
            p.submit(work, status_name)
            for status_name in ("status1", "status2", "status3")
        ]
        done = []
        for f in as_completed(futures):
            done.append(f.result())
            status.update(f"[bold green]Done tasks: {','.join(done)}")
        status.update("[bold green]All are done!!!")


if __name__ == "__main__":
    demo()

asciicast

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multiprog-1.0.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

multiprog-1.0.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file multiprog-1.0.0.tar.gz.

File metadata

  • Download URL: multiprog-1.0.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.6

File hashes

Hashes for multiprog-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5c57666bdd900ed3e4b350dd79bb98f26bd81e0c6575f1da146f665c12d91c65
MD5 10df70f6633621a78f15083cf2b24f94
BLAKE2b-256 4692f0008b1c00c5a03bd9a531059464cc277b5fa690b5ac9bbc9f41cd0dcc92

See more details on using hashes here.

File details

Details for the file multiprog-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: multiprog-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.6

File hashes

Hashes for multiprog-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 77c6b40e505400b2a0cd8aad19287d407885caf8869ee477024f2a0ef29da1b3
MD5 e7b1083d24f491c7c275f3597c233b7f
BLAKE2b-256 5e48a56ff169ce197198ba307dd28e6c6f759263f8b4b3bd096bf49146be0737

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page