Pythonretrying重试装饰器的使用

网友投稿 597 2022-05-30

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

依赖

pip install retrying

1

示例

# -*- 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 """

1

2

3

4

5

6

7

8

9

10

11

Python:retrying重试装饰器的使用

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

参数说明(待补充)

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

参考

Python重试模块retrying

Python

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:三、HDFS中的Python 和JavaAPI
下一篇:PyMySQL 的安装
相关文章