Skip to content
RED SAGSkills
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)
Choose one answer