Nithin Krishnamurthi
01/31/2025, 10:46 PMMarvin
01/31/2025, 10:46 PMPrefectFuture
without blocking the event loop, you can use the add_done_callback
method provided by the PrefectFuture
class. This method allows you to register a callback function that will be executed once the future completes, thus avoiding the need to block the event loop.
Here's a simple example:
python
from prefect import flow, task
from prefect.futures import PrefectFuture
@task
def my_task():
return "result"
def my_callback(future: PrefectFuture):
print(f"Task completed with result: {future.result()}")
@flow
def my_flow():
future = my_task.submit()
future.add_done_callback(my_callback)
my_flow()
In this example, my_callback
will be called when my_task
completes, allowing you to handle the result without blocking the event loop.
For more details, you can refer to the Prefect source code and documentation:
- Prefect futures source code
- Prefect task runners documentationNate
01/31/2025, 10:47 PMasubmit()
aresult()
etc
see https://github.com/PrefectHQ/prefect/issues/15008Nithin Krishnamurthi
01/31/2025, 11:55 PMNithin Krishnamurthi
02/01/2025, 12:01 AMNate
02/01/2025, 12:04 AMNate
02/01/2025, 12:05 AMNithin Krishnamurthi
02/01/2025, 12:19 AMNate
02/01/2025, 12:52 AMNithin Krishnamurthi
02/03/2025, 6:21 PMNate
02/03/2025, 7:43 PMNate
02/03/2025, 7:44 PMNithin Krishnamurthi
02/03/2025, 7:55 PM