question 384 Async Python · easy
A capped exponential backoff schedule
A retrying client waits between attempts: base, then twice that, then twice again, but never longer than cap. Write backoff_schedule(attempts, base, cap) that returns the waits between attempts attempts (there is no wait after the last one).
Function
backoff_schedule(attempts, base, cap)Returnsa list of
attempts - 1 waits: min(base * 2 ** i, cap) for i = 0, 1, …; an empty list for 0 or 1 attemptsExamples
callbackoff_schedule(5, 0.5, 3)returns[0.5, 1.0, 2.0, 3.0]
callbackoff_schedule(3, 1, 60)returns[1.0, 2.0]
callbackoff_schedule(1, 0.5, 10)returns[]