mirror of
https://github.com/codeflash-ai/codeflash.git
synced 2026-05-04 18:25:17 +00:00
16 lines
447 B
Python
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
|