Jack P
04/23/2024, 5:12 PMas_completed
method or something in Prefect-Dask to be able to loop through PrefectFutures as they complete?Marvin
04/23/2024, 5:13 PMas_completed
method, they do reference the use of PrefectFuture
, which is an object that provides access to a computation happening in a task runner.
Typically, when dealing with Dask, you might use the as_completed function to iterate over futures as they complete. This capability may not be directly exposed through Prefect's interface based on the documentation excerpts.
However, with Prefect and Dask integration, you can submit tasks within a DaskTaskRunner
flow, and Prefect handles the task dependencies automatically. In the code example provided in the snippet, tasks are submitted and Prefect manages their execution order according to dependencies, but it does not show a looping mechanism over completed futures.
For more information on how Prefect integrates with Dask, please refer to the Prefect Dask documentation here. For general concepts around PrefectFuture
and task runners, you can read more in the Prefect documentation here.
If you need to process results as they complete, you may have to fetch the futures' results and handle them manually within your flow or use Dask's methods directly by interacting with the `DaskTaskRunner`'s underlying Dask client.Nate
04/23/2024, 6:07 PMtask_runner
you choose
import asyncio
from prefect import flow, task
@task
async def sleep(duration: int) -> int:
await asyncio.sleep(duration)
return duration
@flow
async def as_completed_flow() -> None:
for result in asyncio.as_completed(
[future.result() for future in await sleep.map(range(5))]
):
print(await result)
if __name__ == "__main__":
asyncio.run(as_completed_flow())
Jack P
04/23/2024, 11:26 PMNate
04/24/2024, 12:40 AMJack P
04/24/2024, 1:23 AMNate
04/24/2024, 1:58 AMsync api requestdoes it have to be sync? based on this
loop through PrefectFutures as they completeI feel like I might want to make things async and use
as_completed
something like the aboveJack P
04/24/2024, 2:00 AMNate
04/24/2024, 2:05 AM