繁体   English   中英

Quart 中的 aiohttp.ClientSession()

[英]aiohttp.ClientSession() in Quart

如何创建 aiohttp.ClientSession() 一次,以便在收到请求时可以使用它? 我也想稍后用 Gunicorn 部署它。

您可以通过 before_serving 装饰器使用启动 function

@app.before_serving
async def startup():
    app.client = aiohttp.ClientSession()

@app.get("/")
async def index():
    await app.client.get(...)

由于 Quart 是一个 ASGI 框架,您需要使用 ASGI 服务器,例如 Hypercorn 而不是 Gunicorn(一个 WSGI 服务器)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM