Retry

class Retry(retries=3, exceptions=None, predicate=None, blacklist=None, deadline=None, initial=0.1, maximum=60, jitter=(0, 1), multiplier=2.0)[source]

Retry class to wrap functions as a decorator or inline.

Example

>>> import descarteslabs as dl
>>> retry = dl.common.retry.Retry(
...     maximum=30,
...     retries=5,
...     exceptions=(dl.client.exceptions.GatewayTimeoutError,)
... )
>>> @retry
... def flaky(x):
...    return x
>>> flaky("test")
'test'
>>> retry(lambda x: x)("test")
'test'

Instantiate a Retry object that can be used to wrap a callable.

Parameters
  • retries (int, optional) – The number of retries allowed.

  • exceptions (tuple, optional) – A tuple of Exceptions that should always be retried.

  • predicate (function, optional) – A callable that takes an exception and returns true if retryable. This can be used for cases where a generic exception with variable attributes.

  • blacklist (tuple, optional) – A tuple of Exceptions that should never be retried.

  • deadline (float, optional) – The deadline in seconds for retries.

  • initial (float) – The amount of delay for the before the first retry.

  • maximum (float) – The maximum amount of delay between retries.

  • jitter (tuple, optional) – The bounds for a random amount to be added to each delay.

  • multiplier (float, optional) – The multiple by which the delay increases.

exception RetryError(message, exceptions)[source]

Error raised when the number of retries has been exhausted or the deadline has passed.

property exceptions

Get a list of exceptions that occurred.

Returns

The list of exceptions

Return type

list

truncated_delay_generator(initial=None, maximum=None, jitter=None, multiplier=2.0)[source]

A generator for truncated exponential delay.

Parameters
  • initial (float) – The amount of delay for the first generated value.

  • maximum (float) – The maximum amount of delay.

  • jitter (tuple, optional) – The bounds for a random amount to be added to each delay.

  • multiplier (float, optional) – The multiple by which the delay increases.