This module is a low-level helper, many client libraries have protocol-aware retry logic built in. Check your library before using this.
Policies for retrying an operation safely.
A policy for retrying operations.
Policies are meant to be used as an iterable:
for time_remaining in RetryPolicy.new(attempts=3): try: some_operation.do(timeout=time_remaining) break except SomeError: pass else: raise MaxRetriesError
Return an iterator which controls attempts.
On each iteration, the iterator will yield the number of seconds left to retry, this should be used to set the timeout on the operation being carried out. If there is no maximum time remaining,
Noneis yielded instead.
The iterable will raise
StopIterationonce the operation should not be retried any further.
Return the result of
This allows policies to be directly iterated over.
new(attempts=None, budget=None, backoff=None)¶
Create a new retry policy with the given constraints.
- Return type