其他分享
首页 > 其他分享> > 循环中requests模块偶尔卡死,timeout无济于事,超时跳出方法

循环中requests模块偶尔卡死,timeout无济于事,超时跳出方法

作者:互联网

循环requests时候,未知原因,偶尔会卡死,不报错也不继续,timeout参数无效,解决办法如下
使用eventlet,代码如下,用于循环之内
import eventlet

eventlet.monkey_patch()#这行必须有
time_limit = 30 #(循环中)30s未完成一次循环,则强行重启本次循环
while 1:
    with eventlet.Timeout(time_limit, False):
        res = requests.get(url=url,params=param,headers=headers)
        break

 

标签:eventlet,url,循环,limit,timeout,requests,超时
来源: https://www.cnblogs.com/haaiso/p/14984400.html