Python:retrying重试装饰器的使用
Python 装饰 重试 使用
2023-09-14 09:07:13 时间
文档: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中矩阵的转置怎么写_Python 矩阵转置的几种方法小结
- aic准则python_Python数据科学:线性回归
- python电脑版微信-微信PC版的API接口 | 可通过Python调用微信功能
- Python&R语言-python和r相遇
- java与python-如何对比Python和Java,只需三分钟告诉你!
- 【测试开发】python系列教程:第一个Python程序
- python定义函数求和_Python定义函数实现累计求和操作
- Python中的装饰器
- python-Python与MongoDB数据库-处理MongoDB查询结果
- Python 中 Requests 库的用法详解编程语言
- python实现爬虫下载美女图片详解编程语言
- 革命性技术:Python与MSSQL的携手合作(python和mssql)
- python访问sqlserver示例