您当前的位置: 首页 >  Python

彭世瑜

暂无认证

  • 1浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Python:retrying重试装饰器的使用

彭世瑜 发布时间:2021-01-06 14:12:52 ,浏览量:1

文档:https://pypi.org/project/retrying/

依赖

pip install retrying

示例

# -*- coding: utf-8 -*-

from retrying import retry

# 最多执行5次
@retry(stop_max_attempt_number=5)
def foo():
    print("foo")
    raise Exception("Exception")


if __name__ == '__main__':
    foo()

"""
输出结果:
foo
foo
foo
foo
foo

Traceback (most recent call last):
...
Exception: Exception
"""

参数说明(待补充)

stop 
wait
stop_max_attempt_number         最大重试次数
stop_max_delay                  最大延迟时间(毫秒)
wait_fixed                      每次方法执行之间的等待时间
wait_random_min                 随机的等待时间
wait_random_max                 随机的等待时间
wait_incrementing_start 
wait_incrementing_increment     每调用一次增加固定时长
wait_exponential_multiplier 
wait_exponential_max
retry_on_exception
retry_on_result
wrap_exception
stop_func
wait_func
wait_jitter_max

参考 Python重试模块retrying

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.0928s