Python:retrying重试装饰器的使用

简介: Python:retrying重试装饰器的使用

文档: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
相关文章
|
20天前
|
测试技术 Python
Python装饰器:为你的代码施展“魔法”
Python装饰器:为你的代码施展“魔法”
200 100
|
28天前
|
设计模式 缓存 监控
Python装饰器:优雅增强函数功能
Python装饰器:优雅增强函数功能
238 101
|
20天前
|
缓存 Python
Python装饰器:为你的代码施展“魔法
Python装饰器:为你的代码施展“魔法
131 88
|
1月前
|
缓存 测试技术 Python
Python装饰器:优雅地增强函数功能
Python装饰器:优雅地增强函数功能
171 99
|
1月前
|
存储 缓存 测试技术
Python装饰器:优雅地增强函数功能
Python装饰器:优雅地增强函数功能
151 98
|
1月前
|
缓存 Python
Python中的装饰器:优雅地增强函数功能
Python中的装饰器:优雅地增强函数功能
|
1月前
|
存储 缓存 测试技术
理解Python装饰器:简化代码的强大工具
理解Python装饰器:简化代码的强大工具
|
2月前
|
程序员 测试技术 开发者
Python装饰器:简化代码的强大工具
Python装饰器:简化代码的强大工具
181 92
|
28天前
|
缓存 测试技术 Python
解锁Python超能力:深入理解装饰器
解锁Python超能力:深入理解装饰器
79 2

推荐镜像

更多