美文网首页
http retry

http retry

作者: 潘旭 | 来源:发表于2019-10-09 09:40 被阅读0次

<font size=5> Retrying </font>

http 请求时候的retry, 当失败时候需要进行重试。而 在python中有 retry 库可以使用。
pip install retrying 安装即可。

参数解析

  • stop_max_attempt_number - 尝试次数
  • wait_fixed - 失败后,sleep 时间 再尝试
  • stop_max_delay - 从调用开始 到当前时间最长delay多久

设计原理

self.stop = lambda attempts, delay: any(f(attempts, delay) for f in stop_funcs)

尝试所有的stop函数,只要有一个满足stop要求就stop。这里 any 函数. 下面着重说一下 anyall

Any

只要有一个是True 就返回True.

s = any([True, False, 0, ""])
s
True

All

只有全是True才返回True

s = all([True, False, 0, ""])
s
False

相关文章

网友评论

      本文标题:http retry

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