import requests
requests.get(path_url, timeout=100)
在 python requests 库的上述用法中,一旦 requests.get 运行完毕,连接是否会自动关闭?如果没有,我如何确定连接已关闭
是的,有一个电话session.close
在...后面get
代码。如果使用合适的 IDE(例如 PyCharm),您可以按照get
代码来看看发生了什么。里面get
有一个电话要求:
return request('get', url, params=params, **kwargs)
在该定义内request
方法,调用session.close
被制成。
通过点击链接here https://github.com/requests/requests/blob/master/requests/api.py#L57在请求存储库中,正在对会话控制进行调用:
# By using the 'with' statement we are sure the session is closed, thus we
# avoid leaving sockets open which can trigger a ResourceWarning in some
# cases, and look like a memory leak in others.
with sessions.Session() as session:
return session.request(method=method, url=url, **kwargs)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)