medium10 pts · first answer countspythonreliability
Tracing a retry helper
What does this Python code print?
calls = 0
def flaky():
global calls
calls += 1
if calls < 3:
raise TimeoutError()
return "ok"
def retry(fn, max_retries=4):
for attempt in range(max_retries):
try:
return fn(), attempt
except TimeoutError:
pass
return None, max_retries
print(retry(flaky), calls)Discussion 0
Join free to post in the discussion.
Related questions
- What a hallucination isAI Engineer (LLM & Generative AI)
- Handling an HTTP 429 responseAI Engineer (LLM & Generative AI)
- Parsing a JSON reply in PythonAI Engineer (LLM & Generative AI)
- Getting reliable JSON outputAI Engineer (LLM & Generative AI)
- Why add jitter to backoffAI Engineer (LLM & Generative AI)
- Cosine of a scaled vectorAI Engineer (LLM & Generative AI)
- Agent stuck in a loopAI Engineer (LLM & Generative AI)
- One failure in Promise.allAI Engineer (LLM & Generative AI)