Using Prefect 2 with FastAPI, RuntimeError on event loop #8658
Unanswered
soleilchang
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to use FastAPI + Prefect 2(2.8.3), the idea is to use RESTful API defined in FastAPI to trigger workflow defined in Prefect.
Code as following:
main.py
test_workflow.py
Need to run the following commands to enable the services:
$ prefect server start
$ uvicorn main:app --reload
When I try GET /test, the following error encountered:
RuntimeError: <asyncio.locks.Event object at 0x7f0de4d19bd0 [unset]> is bound to a different event loop
If I define as asynchronous function in FastAPI
async def trigger()
: it will finish without error. But the problem is that, in this way FastAPI can only handle one/test
request at a time (because the workflow is supposed to be blocking that needs time to finish).If it is defined without
async
, normally FastAPI should run it in its ThreadPool to avoid blocking, but got the error as above.Any idea on this?
Beta Was this translation helpful? Give feedback.
All reactions