Jean-Michel Provencher
01/16/2023, 6:54 PMAnna Geller
01/16/2023, 6:57 PMfrom prefect import task, flow
@task
def special_data():
return 42
@task
def extract_data():
return special_data.fn()
@flow(log_prints=True)
def get_data():
x = extract_data()
print(x)
if __name__ == "__main__":
get_data()
Jean-Michel Provencher
01/16/2023, 6:58 PMread_secret.fn(
secret_name=A_SECRET_NAME),
aws_credentials=aws_credentials,
)
return a coroutineNate
01/16/2023, 7:50 PMread_secret.fn
call
In [2]: async def read_secret():
...: return 42
...:
In [3]: read_secret()
Out[3]: <coroutine object read_secret at 0x7fa7004f5170>
In [4]: await read_secret()
Out[4]: 42
Jean-Michel Provencher
01/16/2023, 8:57 PMNate
01/16/2023, 9:35 PMasyncio.run(my_async_flow())
if you don't already have an event loop
• just await my_async_flow()
if you're somewhere that already has an event loop (like ipython in example below)
In [19]: async def read_secret() -> int:
...: return 42
In [20]: @flow(log_prints=True)
...: async def my_async_flow():
...: print(await read_secret())
In [21]: await my_async_flow()
15:32:02.584 | INFO | prefect.engine - Created flow run 'groovy-penguin' for flow 'my-async-flow'
15:32:03.889 | INFO | Flow run 'groovy-penguin' - 42
15:32:04.113 | INFO | Flow run 'groovy-penguin' - Finished in state Completed()