You can access the count of retries in Python retrying library by using the attempt_number attribute of the RetryCallState object.

Here's an example:

from retrying import retry

@retry(wait_fixed=1000, stop_max_attempt_number=3)
def my_function():
    print("Attempt number:", my_function.retry_state.attempt_number)
    raise ValueError("Oops!")

my_function()

In this example, the my_function is decorated with the @retry decorator, which specifies that the function should be retried with fixed wait time of 1 second and a maximum of 3 attempts.

Inside the function, we can access the RetryCallState object using the retry_state attribute. We then print the current attempt number using the attempt_number attribute.

When we run the function, we'll see the following output:

Attempt number: 1
Attempt number: 2
Attempt number: 3
Traceback (most recent call last):
  ...
ValueError: Oops!

As you can see, the function is retried 3 times, and the attempt number is printed each time

how to check the count of retry in python retrying library

原文地址: https://www.cveoy.top/t/topic/dhl0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录