Reference

waiter

class waiter.waiter(delays, timeout=inf)[source]

An iterable which sleeps for given delays.

Parameters
  • delays – any iterable of seconds, or a scalar which is repeated endlessly

  • timeout – optional timeout for iteration

Stats

Stats class attribute

stats

Stats instance attribute

__add__(step)waiter.waiter[source]

Generate incremental backoff.

__aiter__()[source]

Asynchronously generate a slow loop of elapsed time.

__ge__(floor)waiter.waiter[source]

Limit minimum delay generated.

__getitem__(slc: slice)waiter.waiter[source]

Slice delays, e.g., to limit attempt count.

__init__(delays, timeout=inf)[source]

Initialize self. See help(type(self)) for accurate signature.

__iter__()[source]

Generate a slow loop of elapsed time.

__le__(ceiling)waiter.waiter[source]

Limit maximum delay generated.

__mul__(factor)waiter.waiter[source]

Generate exponential backoff.

classmethod accumulate(*args, **kwargs)waiter.waiter[source]

Create waiter based on itertools.accumulate (requires Python 3).

classmethod count(*args, **kwargs)waiter.waiter[source]

Create waiter based on itertools.count.

classmethod exponential(base, **kwargs)waiter.waiter[source]

Create waiter with exponential backoff.

classmethod fibonacci(delay, **kwargs)waiter.waiter[source]

Create waiter with fibonacci backoff.

filtered(predicate: Callable, func: Callable, iterable: Iterable) → Iterator[tuple][source]

Provisionally generate arg, func(arg) pairs while predicate evaluates to true.

map(func: Callable, *iterables: Iterable)waiter.waiter[source]

Return new waiter with function mapped across delays.

poll(predicate, func, *args, **kwargs)[source]

Repeat function call until predicate evaluates to true.

polling(predicate: Callable)[source]

Return a decorator for poll.

classmethod polynomial(exp, **kwargs)waiter.waiter[source]

Create waiter with polynomial backoff.

random(start, stop)waiter.waiter[source]

Add random jitter within given range.

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

Repeat function call.

repeating(func: Callable)[source]

A decorator for repeat.

retry(exception, func, *args, **kwargs)[source]

Repeat function call until exception isn’t raised.

retrying(exception: Exception)[source]

Return a decorator for retry.

stream(queue: Sequence, size: int = None) → Iterator[source]

Generate chained values in groups from an iterable.

The queue can be extended while in use.

suppressed(exception, func: Callable, iterable: Iterable) → Iterator[tuple][source]

Provisionally generate arg, func(arg) pairs while exception isn’t raised.

throttle(iterable)[source]

Delay iteration.

suppress

waiter.suppress(*exceptions)[source]

Variant of contextlib.suppress, which also records exception.

first

waiter.first(predicate: Callable, iterable: Iterable, *default)[source]

Return first item which evaluates to true, like any with filtering.

Stats

class waiter.Stats(**kwds)[source]

Bases: collections.Counter

Mapping of attempt counts.

Note

The Stats interface is considered provisional. It can be customized by overriding at the class or instance level.

add(attempt, elapsed)[source]

Record attempt and return next value.

property failures

number of repeat attempts

property total

total number of attempts