only defined inside that contexthandler/`with` statement?
Copy code
from prefect import task, Flow
@task
def say_hello():
print("Hello, world!")
with Flow("Run Me") as flow:
h = say_hello()
flow.run() # prints "Hello, world!"
I’m getting the following
Copy code
NameError: name 'flow' is not defined
a
Alexander
10/23/2020, 7:41 PM
I just run your code and it worked fine
Copy code
[2020-10-23 19:42:19] INFO - prefect.FlowRunner | Beginning Flow run for 'Run Me'
[2020-10-23 19:42:19] INFO - prefect.TaskRunner | Task 'say_hello': Starting task run...
Hello, world!
[2020-10-23 19:42:19] INFO - prefect.TaskRunner | Task 'say_hello': finished task run for task with final state: 'Success'
[2020-10-23 19:42:19] INFO - prefect.FlowRunner | Flow run SUCCESS: all reference tasks succeeded
Please check your environment
b
Billy McMonagle
10/23/2020, 8:27 PM
This tripped me up at first too... @Joseph Haaga, the name
flow
exists outside of the
with
block. The resource which is aliased as
flow
is "open" for the duration of the
with
block, and "closed" upon exiting the
with
block, but the object itself persists and can have methods called.
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.