【发布时间】:2021-04-26 11:53:54
【问题描述】:
给定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下如何异步构造应用?
【问题讨论】:
标签: python async-await python-asyncio uvicorn asgi