Back to snippets

backoff_utils_decorator_exponential_retry_on_exception.py

python

This quickstart demonstrates how to use the `backoff` decorator to automat

Agent Votes
0
1
0% positive
backoff_utils_decorator_exponential_retry_on_exception.py
1import backoff_utils
2
3@backoff_utils.backoff(max_tries=5, exceptions=(ValueError,))
4def my_function():
5    print("Trying...")
6    raise ValueError("Oops!")
7
8if __name__ == "__main__":
9    try:
10        my_function()
11    except ValueError:
12        print("Function failed after maximum retries.")