Alex Ilyin
12/19/2024, 5:23 PM.result()
function on tasks but run tasks concurrentlyMarvin
12/19/2024, 5:23 PM.result()
function in Prefect, you can use task runners that facilitate parallel execution. Prefect provides several task runners like ThreadPoolTaskRunner
, DaskTaskRunner
, and RayTaskRunner
to handle concurrent or parallel task execution.
1. Concurrent Task Execution:
Use task runners to execute tasks concurrently. For example, the ThreadPoolTaskRunner
runs tasks concurrently within a thread pool, allowing you to submit tasks using the .submit()
method. Each submitted task returns a PrefectFuture
object, which you can use to access the task's state and result.
Learn more about task runners for concurrent execution here: Prefect Task Runners Documentation
2. Retrieving Task Results:
After submitting tasks using .submit()
, you can retrieve their results with the .result()
method on the PrefectFuture
objects returned. This is useful when you want to wait for tasks to complete and get their output.
For details on using .result()
, explore this: Deferred Tasks Documentation
By using these features, you can efficiently run tasks concurrently and handle their results without blocking execution. It's like having a team of diligent scribes working in parallel but still getting your important notes together in the end—how utterly delightful!Nate
12/19/2024, 5:24 PMIn [1]: from prefect import flow, task
In [2]: @flow
...: def f(): task(lambda x: x +1).map(range(3)).result()
In [3]: f()
09:24:14.479 | INFO | prefect.engine - Created flow run 'literate-prawn' for flow 'f'
09:24:14.839 | INFO | Task run '<lambda>-8d2' - Finished in state Completed()
09:24:14.840 | INFO | Task run '<lambda>-2cc' - Finished in state Completed()
09:24:14.841 | INFO | Task run '<lambda>-df1' - Finished in state Completed()
09:24:15.009 | INFO | Flow run 'literate-prawn' - Finished in state Completed()
Alex Ilyin
12/19/2024, 5:27 PM.result(raise_on_failure)
after submitting tasks, it seems to only run 1 task at a timeAlex Ilyin
12/19/2024, 5:27 PMNate
12/19/2024, 5:28 PMAlex Ilyin
12/19/2024, 5:30 PMAlex Ilyin
12/19/2024, 5:30 PMAlex Ilyin
12/19/2024, 5:30 PMAlex Ilyin
12/19/2024, 5:30 PM