美文网首页
解决Unclosed client session

解决Unclosed client session

作者: 飞跑的蛤蟆 | 来源:发表于2020-05-07 17:20 被阅读0次

之前在使用aiohttp时报出这个警告Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x000002ADCEE00AC8>,大概就是client session没有关闭。

可是我明明关了啊,session.close()

从网上找了找,应该是版本问题,解决方案如下:

async def get(url):
    session = aiohttp.ClientSession()
    response = await session.get(url)
    result = await response.text()
    await session.close()  # 在原先代码的前面加上await就没有警告了
    return result

参考资料
aiohttp: Unclosed client session client_session(stackoverflow)

相关文章

网友评论

      本文标题:解决Unclosed client session

      本文链接:https://www.haomeiwen.com/subject/tonaghtx.html