Retries and timeouts

Networks drop and servers get busy. The library tries a failed request again for you, so a short problem doesn't stop your script. This page says what it retries, how long it waits, and how to change that.

What gets retried

The library tries again when:

  • the server answers with 429 (too many requests) or 500, 502, 503 or 504;
  • no answer arrives at all, because the connection dropped or the request timed out.

By default it retries up to 3 times, so a request is sent at most 4 times. Other errors, such as 404 or 422, mean your request is wrong. Sending it again won't help, so the library raises the error at once.

How long it waits

If the server sends a Retry-After header, the library waits that many seconds. The request limit does this when you go over it.

Otherwise it waits longer each time, with a little randomness added so many scripts don't all retry together:

How long it waits
RetryWait
FirstAbout 0.5 to 1 second
SecondAbout 1 to 1.5 seconds
ThirdAbout 2 to 2.5 seconds

If every try fails, you get the last error: a RateLimitError or APIServerError for a bad answer, or a NetworkError when nothing answered.

Writes are safe to retry

A retry could run a write twice, such as creating two projects. To prevent that, the library adds an idempotency key to every POST, PUT, PATCH and DELETE, and uses the same key on every try. The server then does the work once. See Idempotency.

Change the settings

python
client = Client(max_retries=5, timeout=60)

max_retries=0 turns retrying off. timeout is how many seconds the library waits for the server on one request, and the default is 30.

The request limit

ThrustLab allows each API key 1,000 requests a minute, with a burst of up to 50 at once. A script that polls often, or loops over many calls, can reach that. When it does, the library waits and retries. See Rate limits for more.

Submitting runs has its own limit for each minute, and it is lower. A 429 with the code create_rate_limited means you sent too many runs in a minute. Retry after the pause, or put many settings into one sweep.

Waiting for runs is separate

The timeout here only covers one request. How long you wait for a run to finish is a different setting on wait. See Async resources.