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
KazooRetryinstance for retrying function calls.
- Parameters:
max_tries (
int|None) – How many times to retry the command. -1 means infinite tries.delay (
float) – Initial delay between retry attempts.backoff (
int) – Backoff multiplier between retry attempts. Defaults to 2 for exponential backoff.max_jitter (
float) – 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 (
float) – Maximum delay in seconds, regardless of other backoff settings. Defaults to one minute.ignore_expire (
bool) – Whether a session expiration should be ignored and treated as a retry-able command.interrupt (
Callable[[],bool] |None) – 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 (Callable[…, RETRY_RETURN]) – Function to call
args (Any) – Positional arguments to call the function with
- Params kwargs:
Keyword arguments to call the function with
- Return type:
RETRY_RETURN
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.
- exception kazoo.retry.ForceRetryError[source]¶
Raised when some recipe logic wants to force a retry.