Andrew M
01/12/2025, 9:39 PMMarvin
01/12/2025, 9:39 PMMarvin
01/12/2025, 9:39 PM.submit
and `.map`: Even if the underlying user function is asynchronous, Prefect's .submit
and .map
methods are synchronous. They return futures that represent the eventual completion of the task, but they don't need to be awaited themselves. Instead, you handle them in a non-blocking way.
2. Handling Futures: The futures returned by .submit
or .map
can be resolved by:
- Passing them to another task.
- Returning them from a task or flow.
- Manually calling .result()
or .wait()
on them.
3. Event Loop Issue: The error you're encountering ("Event loop is closed") might arise if there's a conflict in how the event loop is being managed. Prefect manages its own event loop, and mixing it with other async libraries, like `httpx`'s AsyncClient
, can sometimes cause issues.
4. Avoiding await
on Futures: You should not use await
on the futures returned by .submit
or .map
directly because they are not asyncio-compatible futures. Instead, use .result()
or .wait()
to handle them.
For more detailed information, you can refer to the Prefect task documentation and flow engine documentation.
If you have a specific setup or stack configuration, let me know, and I can provide more tailored advice.