给定main.py
:
import asyncio
async def new_app():
# Await some things.
async def app(scope, receive, send):
...
return app
app = asyncio.run(new_app())
其次是:
uvicorn main.app
给出:
RuntimeError: asyncio.run() cannot be called from a running event loop
这是因为uvicorn
在导入我的应用程序之前已经启动了一个事件循环。如何在 下异步构建应用程序uvicorn
?