Spaces:
Sleeping
Sleeping
| # utils.py | |
| import time | |
| # Function to retry a given function with exponential backoff in case of failure | |
| def retry_with_backoff(func, max_retries=5, backoff_factor=0.2): | |
| for attempt in range(max_retries): | |
| try: | |
| # Try executing the function | |
| return func() | |
| except Exception as e: | |
| # If the maximum number of retries is reached, raise the exception | |
| if attempt == max_retries - 1: | |
| raise e | |
| # Sleep for an exponentially increasing duration before retrying | |
| time.sleep(backoff_factor * (2 ** attempt)) | |