runtime
476 / 500
question 476 Observability & Operations · medium

The retry that hides failures

Two complaints about fetch_with_retry: a request with a malformed repository name takes seven seconds of waiting before anything happens, and when the star service is completely down, callers get None and show "0 stars" instead of an error. Fix it: retry only TimeoutError, wait 2**n seconds through sleep between tries, and re-raise when the tries run out.

Functionfetch_with_retry(fetch, repo, sleep, attempts=4)
Retryonly TimeoutError; any other exception is raised at once, without waiting
Waitssleep(2**n) before the next try (1, 2, 4 …)
Returnsfetch(repo)'s result; raises the last TimeoutError after attempts tries

Loading your progress…

The retry that hides failures — Python practice · Runtime