Skip to main content

ExpBackoff

An exponential backoff implementation as described in an AWS architecture post. Uses full jitter.

Example

from expbackoff import Backoff

backoff = Backoff(base_seconds=0.5, max_seconds=120)

while True:
    backoff.sleep() # Depending on previous failures, potentially delay before performing an action
    success = do_a_thing() # Perform an action, record whether it succeeded
    backoff.update(success) # Update the failure count

API

  • backoff = expbackoff.Backoff(...)

  • Create a Backoff object. Arguments:

    • base_seconds (required): Part of the backoff calculation, i.e base_seconds * 2 ^ (failures - 1)

    • max_seconds (required): Max seconds to delay, regardless of failure count.

    • failures (optional): Number of current failures. Useful if another service is handling your retries. Defaults to 0.

    • random (optional): A random object. Defaults to random.random.

  • backoff.sleep(): If failures have occurred, sleep for backoff.get_seconds_with_jitter()

  • backoff.update(success): Update the failure count by passing a boolean representing success.

  • backoff.get_seconds_with_jitter(): The current backoff time in seconds, with jitter applied. Zero if there are no recorded failures. Read-only.

  • backoff.get_raw_seconds(): The current backoff time in seconds, without jitter applied. Zero if there are no recorded failures. Read-only.

  • backoff.failures: The current number of failures. Read-only.

Alternatives

Popular options are retrying and backoff. These both use a decorator API so aren’t suitable for all uses - hence expbackoff.

Release files for expbackoff 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for expbackoff 0.1.1
File Size Uploaded
expbackoff-0.1.1.tar.gz 2.5 kB Details

Release files / expbackoff-0.1.1.tar.gz

Download URL expbackoff-0.1.1.tar.gz
Size 2.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b8549bbb512aa5808992d60796612e25e0691dcd71e3ba67b6e92c32782df909
BLAKE2b-256 checksum
How to use checksums
962f8fd314cc28e264e6c090095546bec1e076c72c38ced175b00244cddb6e4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page