Skip to content
Discussion options

You must be logged in to vote

Yes — you can update the total of a running task via progress.update(). The track() helper doesn't expose this directly, but you can switch to the manual API which gives you full control:

from rich.progress import Progress

entities = ["valid", "invalid", "valid", "invalid", "valid"]

with Progress() as progress:
    task = progress.add_task("Processing...", total=len(entities))

    for entity in entities:
        if entity == "invalid":
            # Decrease total for invalid entities
            progress.update(task, total=progress.tasks[task].total - 1)
            continue

        # Process valid entity
        progress.update(task, advance=1)

The progress bar will correctly show e…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by NHOrus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants