runtime
384 / 500
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).

Functionbackoff_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 attempts
Examples
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[]

Loading your progress…

A capped exponential backoff schedule — Python practice · Runtime