Alexis Lucido
12/23/2021, 5:19 PMKevin Kho
from prefect import Flow, task
import prefect
import random
def mystatehandler(obj, old_state, new_state):
if new_state.is_finished():
print(prefect.context.rand)
return new_state
@task(state_handlers=[mystatehandler])
def abc(x):
rand = random.random()
prefect.context.rand = rand
return x + rand
with Flow("some_flow_name") as flow:
a = abc(1)
flow.run()
Alexis Lucido
12/23/2021, 5:24 PM