Given main.py:
import asyncio
async def new_app():
# Await some things.
async def app(scope, receive, send):
...
return app
app = asyncio.run(new_app())
followed by:
uvicorn main.app
gives:
RuntimeError: asyncio.run() cannot be called from a running event loop
This is because uvicorn already started an event loop prior to importing my application. How can I asynchronously construct an application under uvicorn?