All Projects → coady → waiter

coady / waiter

Licence: other
Delayed iteration for polling and retries.

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to waiter

Backoff
Python library providing function decorators for configurable backoff and retry
Stars: ✭ 1,670 (+9723.53%)
Mutual labels:  asyncio, retry, backoff, exponential
Retry
A simple, stateless, functional mechanism to perform actions repetitively until successful.
Stars: ✭ 406 (+2288.24%)
Mutual labels:  delay, incremental, retry
Elixirretry
Simple Elixir macros for linear retry, exponential backoff and wait with composable delays
Stars: ✭ 314 (+1747.06%)
Mutual labels:  delay, retry
Resty
Simple HTTP and REST client library for Go
Stars: ✭ 5,368 (+31476.47%)
Mutual labels:  retry, backoff
Failsafe
Fault tolerance and resilience patterns for the JVM
Stars: ✭ 3,541 (+20729.41%)
Mutual labels:  timeout, retry
backoff
PHP library providing retry functionality with multiple backoff strategies and jitter support
Stars: ✭ 132 (+676.47%)
Mutual labels:  retry, backoff
Riprova
Versatile async-friendly library to retry failed operations with configurable backoff strategies
Stars: ✭ 106 (+523.53%)
Mutual labels:  asyncio, retry
php-backoff
Simple back off / retry functionality
Stars: ✭ 24 (+41.18%)
Mutual labels:  retry, backoff
retries
Forget about your retry boilerplate
Stars: ✭ 14 (-17.65%)
Mutual labels:  retry, wait
sleepover
💤 Sleep, snooze & step methods
Stars: ✭ 13 (-23.53%)
Mutual labels:  delay, sleep
awsretry
Decorate your AWS Boto3 Calls with AWSRetry.backoff(). This will allows your calls to get around the AWS Eventual Consistency Errors.
Stars: ✭ 42 (+147.06%)
Mutual labels:  retry, backoff
p3ui
C++ & Python User Interface Library
Stars: ✭ 21 (+23.53%)
Mutual labels:  asyncio
ALT
Non-contact real-time heartbeats and respiration monitoring using Artificial Light Texture (ALT).
Stars: ✭ 41 (+141.18%)
Mutual labels:  sleep
mitm
👨🏼‍💻 ‎‎‎‏‏ A customizable man-in-the-middle TCP proxy.
Stars: ✭ 44 (+158.82%)
Mutual labels:  asyncio
chai
Don't let your Mac fall asleep, like a sir
Stars: ✭ 54 (+217.65%)
Mutual labels:  sleep
simple-matrix-bot-lib
An easy to use bot library for the Matrix ecosystem written in Python. https://matrix.to/#/#simplematrixbotlib:matrix.org
Stars: ✭ 27 (+58.82%)
Mutual labels:  asyncio
binance-chain-python
Binance chain SDK in Python
Stars: ✭ 22 (+29.41%)
Mutual labels:  asyncio
AmimeWatch
Telegram bot made in Python 3 using the @pyrogram framework.
Stars: ✭ 19 (+11.76%)
Mutual labels:  asyncio
hypercorn-fastapi-docker
Docker image with Hypercorn for FastAPI apps in Python 3.7, 3.8, 3.9. Ready for HTTP2 and HTTPS
Stars: ✭ 18 (+5.88%)
Mutual labels:  asyncio
PepperBot
An intuitive multi-platform bot framework, write once, run everywhere. 一个符合直觉的跨社交平台机器人框架,轻松地在平台间传递消息,支持QQ、微信
Stars: ✭ 21 (+23.53%)
Mutual labels:  asyncio

image image image image image image image image image

Does Python need yet another retry / poll library? It needs at least one that isn't coupled to decorators and functions. Decorators prevent the caller from customizing delay options, and organizing the code around functions hinders any custom handling of failures.

Waiter is built around iteration instead, because the foundation of retrying / polling is a slowly executing loop. The resulting interface is both easier to use and more flexible, decoupling the delay algorithms from the application logic.

Usage

creation

Supply a number of seconds to repeat endlessly, or any iterable of seconds.

from waiter import wait

wait(1)                 # 1, 1, 1, 1, ...
wait([1] * 3)           # 1, 1, 1
wait([0.5, 0.5, 60])    # circuit breaker

Iterable delays can express any waiting strategy, and constructors for common algorithms are also provided.

wait.count(1)           # incremental backoff 1, 2, 3, 4, 5, ...
wait(1) + 1             # alternate syntax 1, 2, 3, 4, 5, ...
wait.fibonacci(1)       # 1, 1, 2, 3, 5, ...
wait.polynomial(2)      # 0, 1, 4, 9, 16, ...

wait.exponential(2)     # exponential backoff 1, 2, 4, 8, ...
backoff = wait(1) * 2   # alternate syntax 1, 2, 4, 8, ...
backoff[:3]             # limit attempt count 1, 2, 4
backoff <= 5            # set maximum delay   1, 2, 4, 5, 5, 5, ...
backoff.random(-1, 1)   # add random jitter

iteration

Then simply use the wait object like any iterable, yielding the amount of elapsed time. Timeouts also supported of course.

from waiter import wait, suppress, first

for elapsed in wait(delays):            # first iteration is immediate
    with suppress(exception):           # then each subsequent iteration sleeps as necessary
        ...
        break

for _ in wait(delays, timeout):         # standard convention for ignoring a loop variable
    ...                                 # won't sleep past the timeout
    if ...:
        break

results = (... for _ in wait(delays))   # expressions are even easier
first(predicate, results[, default])    # filter for first true item
assert any(results)                     # perfect for tests too

functions

Yes, functional versions are provided, as well as being trivial to implement.

wait(...).throttle(iterable)                      # generate items from iterable
wait(...).repeat(func, *args, **kwargs)           # generate successive results
wait(...).retry(exception, func, *args, **kwargs) # return first success or re-raise exception
wait(...).poll(predicate, func, *args, **kwargs)  # return first success or raise StopIteration

The decorator variants are simply partial applications of the corresponding methods. Note decorator syntax doesn't support arbitrary expressions.

backoff = wait(0.1) * 2
@backoff.repeating
@backoff.retrying(exception)
@backoff.polling(predicate)

But in the real world:

  • the function may not exist or be succinctly written as a lambda
  • the predicate may not exist or be succinctly written as a lambda
  • logging may be required
  • there may be complex handling of different exceptions or results

So consider the block form, just as decorators don't render with blocks superfluous. Also note wait objects are re-iterable provided their original delays were.

async

Waiters also support async iteration. throttle optionally accepts an async iterable. repeat, retry, and poll optionally accept coroutine functions.

statistics

Waiter objects have a stats attribute for aggregating statistics about the calls made. The base implementation provides total and failure counts. The interface of the stats object itself is considered provisional for now, but can be extended by overriding the Stats class attribute. This also allows customization of the iterable values; elapsed time is the default.

Installation

% pip install waiter

Dependencies

  • multimethod

Tests

100% branch coverage.

% pytest [--cov]

Changes

dev

  • Python >=3.7 required

1.2

  • Python >=3.6 required

1.1

  • Stream from sized groups

1.0

  • Map a function across an iterable in batches

0.6

  • Extensible iterable values and statistics
  • Additional constructors: fibonacci, polynomial, accumulate

0.5

  • Asynchronous iteration

0.4

  • Decorators support methods
  • Iterables can be throttled

0.3

  • Waiters behave as iterables instead of iterators
  • Support for function decorators

0.2

  • suppress context manager for exception handling
  • repeat method for decoupled iteration
  • first function for convenient filtering
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].