Python Retry Library: How to Check Retry Count
You can check the count of retries in the Python retry library by using the 'retry.statistics' module. Here's an example:
from retry import retry, RetryError, statistics
@retry(exceptions=(RetryError,), tries=3)
def my_function():
# Some code here that may raise a RetryError
pass
my_function()
print(statistics.get(my_function)) # Returns a dictionary of statistics
The 'statistics.get()' method returns a dictionary containing the retry statistics for the specified function. The dictionary contains the following keys:
- 'calls': The number of times the function was called (including retries).
- 'failures': The number of times the function raised an exception.
- 'retries': The number of times the function was retried (excluding the initial call).
- 'started_at': The time the first call was made.
- 'ended_at': The time the last call completed.
- 'elapsed_time': The total elapsed time for all calls.
You can use the 'retries' key to get the count of retries.
原文地址: https://www.cveoy.top/t/topic/nDG1 著作权归作者所有。请勿转载和采集!