In an API developed using FastAPI framework, I am using asyncio
to make calls to solr collections, but when I am calling asyncio.run(man(a,b))
from a python file query.py
then I am getting asyncio.run() cannot be called from a running event loop
.
in controller.py
@router.api_route()
async def api_call(a,b):
#calling a function
resp = query(a,b)
return resp
in query.py
def query(a,b):
result = asyncio.run(man(a,b))
return result
in database_call.py
async def man(a,b)
async with aiohttp.ClientSession() as session:
url = ''
async with session.get(pokemon_url) as resp:
result = await resp.json()
return result
when I am calling asyncio.run(man(a,b))
from query then I am getting asyncio.run() cannot be called from a running event loop
. Kindly help me resolve the issue.
I tried: in query.py
def query(a,b):
loop = asyncio.get_event_loop
result = loop.create_task(man(a,b))
return result
then I am getting <coroutine object main at 0x0394999ejt>