Skip to main content

Decorator-based exponential backoff

Project description

Python Backoff Decorator
========================

This package implements exponential backoff as a decorator. Backoff is
triggered by an exception and is reset when the call is successful.


Usage
-----

Apply exponential backoff to any function or method by simply adding the
decorator:

```python
import backoff
import requests

@backoff.Backoff()
def send_data(data):
requests.post('https://example.com/data', data={'data': data})

try:
send_data('foo')
except:
# do something with data that wasn't posted
```

In the example above calls to `send_data()` will exponentially backoff when
POST is not successful.


Calls During Backoff Period
---------------------------

Any calls made during the backoff period will raise an `InBackoff` exception.


Setting Maximum Backoff
-----------------------

By default the maximum backoff is 1 hour. The `max_backoff` argument can be
passed to change the default; the following will only backoff for 5 minutes:

```python
@backoff.Backoff(max_backoff=300)
def send_data(data):
requests.post('https://example.com/data', data={'data': data})
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

exbackoff-1.1.1.tar.gz (2.5 kB view details)

Uploaded Source

File details

Details for the file exbackoff-1.1.1.tar.gz.

File metadata

  • Download URL: exbackoff-1.1.1.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for exbackoff-1.1.1.tar.gz
Algorithm Hash digest
SHA256 70569b1bd6550cb7a4cfab0d579a87371c66a765cf149e248b1cfac7ef56487d
MD5 c24c0a8abf1654cd0dc3d5dedcea71f9
BLAKE2b-256 25997a0f7dd02ef83ca6838a9c3e0e4c7be482ba2e922e156ad0ee02eb6e1e73

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page