kazoo.retry

Public API

class kazoo.retry.KazooRetry(max_tries=1, delay=0.1, backoff=2, max_jitter=0.4, max_delay=60.0, ignore_expire=True, sleep_func=<built-in function sleep>, deadline=None, interrupt=None)[source]

Helper for retrying a method in the face of retry-able exceptions

__init__(max_tries=1, delay=0.1, backoff=2, max_jitter=0.4, max_delay=60.0, ignore_expire=True, sleep_func=<built-in function sleep>, deadline=None, interrupt=None)[source]

Create a KazooRetry instance for retrying function calls.

Parameters:
  • max_tries – How many times to retry the command. -1 means infinite tries.

  • delay – Initial delay between retry attempts.

  • backoff – Backoff multiplier between retry attempts. Defaults to 2 for exponential backoff.

  • max_jitter – Percentage of jitter to apply to each retry’s delay to ensure all clients to do not hammer the server at the same time. Between 0.0 and 1.0.

  • max_delay – Maximum delay in seconds, regardless of other backoff settings. Defaults to one minute.

  • ignore_expire – Whether a session expiration should be ignored and treated as a retry-able command.

  • interrupt – Function that will be called with no args that may return True if the retry should be ceased immediately. This will be called no more than every 0.1 seconds during a wait between retries.

__call__(func, *args, **kwargs)[source]

Call a function with arguments until it completes without throwing a Kazoo exception

Parameters:
  • func – Function to call

  • args – Positional arguments to call the function with

Params kwargs:

Keyword arguments to call the function with

The function will be called until it doesn’t throw one of the retryable exceptions (ConnectionLoss, OperationTimeout, or ForceRetryError), and optionally retrying on session expiration.

reset()[source]

Reset the attempt counter

copy()[source]

Return a clone of this retry manager

exception kazoo.retry.ForceRetryError[source]

Raised when some recipe logic wants to force a retry.

exception kazoo.retry.RetryFailedError[source]

Raised when retrying an operation ultimately failed, after retrying the maximum number of attempts.

exception kazoo.retry.InterruptedError[source]

Raised when the retry is forcibly interrupted by the interrupt function