I haave a challenge with async
/await
blocking other requests in FastAPI. My code used to work well calling requests in def
functions. For instance:
someRequestsApis = APIRouter()
someRequestsApis.get("/something/")
def getThings():
return list(things.find())
Things would work well in this format. Now, I find myself for some reason having to switch from pymongo
to AsyncIOMotorClient
. The thing is I cannot run the motor database apis in my requests without using async
/await
. What used to be:
def getThings():
return list(things.find())
is now supposed to be:
async def getThings():
return await things.find().to_list()
Even the background tasks that are supposed to handle some of this logic have to be asynchronous, yet requests get blocked. I have searched for answers on this issue, yet the answer seems to suggest that the solution has to be to remove async
/await
in my requests and since I seem not to have such a luxury what is my work around strategy for such?