Retries and backoff¶
Tidewater retries a request that fails with a connection error or a 5xx status, waiting longer before each attempt. You choose how many attempts it makes and how the wait grows.
A first example¶
Pass a Retry to the client. This one tries five times, doubling the wait from half a second:
from tidewater import Client, Retry
client = Client(retry=Retry(attempts=5, backoff=0.5))
Note
A request with a body is only retried when the body can be sent again: bytes and files can, generators can’t.
Options¶
Every option has a default that suits most services:
| Option | Default | Meaning |
|---|---|---|
attempts | 3 | How many times to try, the first included. |
backoff | 1.0 | Seconds before the second attempt; doubled after each one. |
statuses | {502, 503, 504} | Statuses worth retrying. Use a|b sets to combine. |
The wait is capped at max_backoff, sixty seconds unless you change it, so a long run of failures never leaves a request waiting for hours.
Giving up¶
When the last attempt fails, the client raises RetryError with every failure attached, oldest first, so you can see whether the service was down or merely slow.