栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python requests 长时间卡死 无反应

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python requests 长时间卡死 无反应

使用多进程的时候requests一定要设置超时时间不然,程序会卡死在进程里

requests文档上有写,timeout is not a time limit on the entire response download; rather, an exception is raised if the server has not issued a response for timeout seconds (more precisely, if no bytes have been received on the underlying socket for timeout seconds). If no timeout is specified explicitly, requests do not time out.

大概的意思就是说requests请求上设置的timeout不是整个响应下载的时间限制,这里的timeout应该理解为与服务器连接后接收数据的时间,如果超过规定的时间则为超时。这与我之前的理解有很大不同。

timeout可以传一个浮点数,也可以传一个元组

如果你设置了一个单一的值作为 timeout,这一 timeout 值将会用作 connect(连接超时) 和 read (读取超时)二者的 timeout

requests.post(url, headers=headers,data=info_json, timeout=(5,10))


 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/929688.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号