Python:retrying重試裝飾器的使用
文檔: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
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小時內刪除侵權內容。