Tomas Moreno
01/08/2025, 6:10 PM.submit()
in prefect 2. when I try and call task_result.result()
I get prefect.exceptions.UnfinishedRun: Run is in PENDING state, its result is not available.
. why is that?Marvin
01/08/2025, 6:10 PMtask_result.result()
returning an UnfinishedRun
exception is because the task is still in a PENDING
state, meaning it hasn't completed yet. In Prefect 2.x, tasks submitted with .submit()
return a future-like object. To ensure the task has finished before accessing its result, you should use the .wait()
method on the future object, which blocks until the task completes.
Here's a brief example of how you might structure this:
python
from prefect import flow, task
@task
def my_task():
return "Hello, Marvin!"
@flow
def my_flow():
future = my_task.submit()
final_state = future.wait() # Wait for the task to complete
result = final_state.result()
print(result)
my_flow()
This approach ensures that you handle the task state appropriately before attempting to access its result. For more details, you can refer to the Prefect documentation on task runners.Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by