Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/async_examples/concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@


async def get_endpoint(session: aiohttp.ClientSession, url: str) -> str:
async with session.get(url) as response:
return await response.text()
await asyncio.sleep(0.1)
return url


async def some_api_call(urls):
Expand All @@ -19,14 +19,16 @@ async def some_api_call(urls):


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.00001 * attempt)
await asyncio.sleep(0.0001 * attempt)
raise last_exception


Expand All @@ -44,5 +46,5 @@ async def sorter(arr):


async def task():
time.sleep(1)
return "done"
time.sleep(0.00001)
return "done"
Loading