context manager basically replace using a
function? i.e., instead of something like this:
from prefect import task, Flow @task def say_hello(): print("Hello, world!") @task def say_goodbye(): print("Goodbye, world!") with Flow("My First Flow") as flow: say_hello() say_goodbye()
be used with the context manager (and is it weird/redundant to do so)? i.e., would you decorate each function with
, order them in
(but not decorate
) and then call
from the context manager like so:
Thanks for any advice/insights on best practices around this!
from prefect import task, Flow @task def say_hello(): print("Hello, world!") @task def say_goodbye(): print("Goodbye, world!") def main(): say_hello() say_goodbye() if __name__ == "__main__": with Flow("My First Flow") as flow: main()
function. 2- Use
to configure my
call, and also customize what to do with the built flow.
Usually I implement a simple CLI inside my
def build_flow(is_polite): with Flow('abc') as f: say_hello() if is_polite: say_goodbye() return flow def main(): # Here I can customize the flow I build without modifying the context manager flow = build_flow(True) # What I wanna do with the flow resides in main separated from what the flow consists of. # flow.run() flow.visualize()
function, so I can pick what I wanna do and build without touching anything in the code.