Reference

wait

waiter.wait

alias of waiter.awaiter.awaiter

waiter

class waiter.base.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)[source]

Generate incremental backoff.

__ge__(floor)[source]

Limit minimum delay generated.

__getitem__(slc)[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)[source]

Limit maximum delay generated.

__mul__(factor)[source]

Generate exponential backoff.

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

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

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

Create waiter based on itertools.count.

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

Create waiter with exponential backoff.

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

Create waiter with fibonacci backoff.

filtered(predicate, func, iterable)[source]

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

map(func, *iterables)[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)[source]

Return a decorator for poll.

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

Create waiter with polynomial backoff.

random(start, stop)[source]

Add random jitter within given range.

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

Repeat function call.

repeating(func)[source]

A decorator for repeat.

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

Repeat function call until exception isn’t raised.

retrying(exception)[source]

Return a decorator for retry.

stream(queue, size=None)[source]

Generate chained values in groups from an iterable.

The queue can be extended while in use.

suppressed(exception, func, iterable)[source]

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

throttle(iterable)[source]

Delay iteration.

awaiter

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

Bases: waiter.base.waiter

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

Note

Overloads for async coroutine functions.

__aiter__()[source]

Generate a slow loop of elapsed time.

poll

Repeat function call until predicate evaluates to true.

repeat

Repeat function call.

retry

Repeat function call until exception isn’t raised.

throttle

Delay iteration.

suppress

waiter.suppress(*exceptions)[source]

Backport of contextlib.suppress, which also records exception.

first

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

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

Stats

class waiter.base.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