codeflash/code_to_optimize/code_directories/async_e2e/main.py
Kevin Turcios fa705e1b5e first pass
2025-09-26 13:53:15 -07:00

16 lines
447 B
Python

import time
import asyncio
async def retry_with_backoff(func, max_retries=3):
if max_retries < 1:
raise ValueError("max_retries must be at least 1")
last_exception = None
for attempt in range(max_retries):
try:
return await func()
except Exception as e:
last_exception = e
if attempt < max_retries - 1:
time.sleep(0.0001 * attempt)
raise last_exception