Will Truong
01/04/2023, 9:49 AMfrom prefect import flow
@flow
def my_favorite_function():
print("What is your favorite number?")
return 42
print(my_favorite_function())
------------------------
ERROR:
Traceback (most recent call last):
at block 1, line 8
at /opt/python/envs/default/lib/python3.8/site-packages/prefect/flows.py, line 448, in __call__(self, return_state, wait_for, *args, **kwargs)
at /opt/python/envs/default/lib/python3.8/site-packages/prefect/engine.py, line 164, in enter_flow_run_engine_from_flow_call(flow, parameters, wait_for, return_type)
at /opt/python/envs/default/lib/python3.8/site-packages/anyio/_core/_eventloop.py, line 70, in run(func, backend, backend_options, *args)
at /opt/python/envs/default/lib/python3.8/site-packages/anyio/_backends/_asyncio.py, line 292, in run(func, debug, use_uvloop, policy, *args)
at /opt/python/lib/python3.8/asyncio/runners.py, line 33, in run(main, debug)
RuntimeError: asyncio.run() cannot be called from a running event loop
Tim-Oliver
01/04/2023, 9:54 AMif __name__ == "__main__":
print(my_favorite_function())
Will Truong
01/04/2023, 9:55 AMTim-Oliver
01/04/2023, 9:57 AMasync def...
). See here: https://docs.prefect.io/tutorials/execution/#asynchronous-executionWill Truong
01/04/2023, 10:01 AMTim-Oliver
01/04/2023, 10:05 AMWill Truong
01/04/2023, 10:06 AMTim-Oliver
01/04/2023, 10:06 AMWill Truong
01/04/2023, 10:06 AMTim-Oliver
01/04/2023, 10:07 AMpython ./your-script.py
?Will Truong
01/04/2023, 10:10 AMBeege (Bryan Berry)
01/04/2023, 10:18 AMasyncio
is a way to run things asynchronously. i'm guessing that Prefect, by default, sets up things to run asynchronously. however, you can only do that set up one time. i think your online IDE is also trying to do this asynchronous set up. i'm trying to see if there's a way for Prefect to not run it asynchronously. you said it works properly locally, yes?Will Truong
01/04/2023, 10:19 AMBeege (Bryan Berry)
01/04/2023, 10:20 AMWill Truong
01/04/2023, 10:21 AMBeege (Bryan Berry)
01/04/2023, 10:22 AMWill Truong
01/04/2023, 10:23 AMBeege (Bryan Berry)
01/04/2023, 10:24 AMmyflow.fn()
, but then you lose a lot of the advantages of Prefectasyncio
Will Truong
01/04/2023, 10:31 AMBeege (Bryan Berry)
01/04/2023, 10:35 AM@flow()
...
to
from prefect.task_runners import TaskConcurrencyType
@flow(task_runner=TaskConcurrencyType.SEQUENTIAL)
see if that works?import asyncio
asyncio.ensure_future(my_favorite_function())
Will Truong
01/04/2023, 10:38 AMBeege (Bryan Berry)
01/04/2023, 10:38 AMWill Truong
01/04/2023, 10:40 AMJeff Hale
01/04/2023, 1:49 PMBeege (Bryan Berry)
01/05/2023, 2:05 AMWill Truong
01/10/2023, 9:54 AMTim-Oliver
01/10/2023, 9:56 AMWill Truong
01/10/2023, 10:02 AMJeff Hale
01/10/2023, 1:07 PMWill Truong
01/10/2023, 1:47 PM