Hi all, Is there a recommended way to report progr...
# prefect-getting-started
s
Hi all, Is there a recommended way to report progress from within a task? For example, if a task is processing some 1000 items, it would be useful to log the completion %. Are there some utilities in prefect that I can use to simplify these type of workflows?
n
hi @Surya - this sounds like a great time for
rich
!
Copy code
from time import sleep
from prefect import flow, task
from rich.progress import Progress

def process_item(item):
    # Simulating some processing time
    sleep(0.1)

@task
def some_task():
    items = list(range(100))

    with Progress() as progress:
        task = progress.add_task("[green]Processing items...", total=len(items))

        for item in items:
            process_item(item)
            progress.update(task, advance=1)

@flow
def some_flow():
    some_task()

if __name__ == "__main__":
    some_flow()
which comes with `prefect`'s install, and you could write a more convenient util if you wanted to avoid boilerplate / use it often
s
This is awesome! I will try this out.
Would tqdm work with the prefect ui as well?
n
ooh im not sure about the UI / how it would look
i would have to experiment!
👍 1
that sounds like a cool feature request, a UI compatible progress bar
💯 1
s
Will try it out and update here
👍 1
t
Ah i just found this which is helpful: https://github.com/tqdm/tqdm/issues/313