retry decorator
Project description
easy to use retry decorator.
Features
No external dependency (stdlib only).
(Optionally) Preserve function signatures (pip install decorator).
Original traceback, easy to debug.
Installation
$ pip install retry
API
def retry(exceptions=Exception, tries=-1, delay=0, backoff=1, logger=logging_logger):
"""Return a retry decorator.
:param exceptions: an exception or a tuple of exceptions to catch. default: Exception.
:param tries: the maximum number of attempts. default: -1 (infinite).
:param delay: initial delay between attempts. default: 0.
:param backoff: multiplier applied to delay between attempts. default: 1 (no backoff).
:param logger: logger.warning(fmt, error, delay) will be called on failed attempts.
default: retry.logging_logger. if None, logging is disabled.
"""
various retrying logic can be achieved by combination of arguments.
Examples
from retry import retry
@retry()
def make_trouble():
'''Retry until succeed'''
@retry(ZeroDivisionError, tries=3, delay=2)
def make_trouble():
'''Retry on ZeroDivisionError, raise error after 3 attempts, sleep 2 seconds between attempts.'''
@retry((ValueError, TypeError), delay=1, backoff=2)
def make_trouble():
'''Retry on ValueError or TypeError, sleep 1, 2, 4, 8, ... seconds between attempts.'''
# If you enable logging, you can get warnings like 'ValueError, retrying in
# 1 seconds'
if __name__ == '__main__':
import logging
logging.basicConfig()
make_trouble()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
retry-0.7.0.tar.gz
(2.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
retry-0.7.0-py2-none-any.whl
(4.8 kB
view details)
File details
Details for the file retry-0.7.0.tar.gz.
File metadata
- Download URL: retry-0.7.0.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2dffe004fe6db975d5e52a19c0d5ab82ac15f2c6737207c48dbade340bcc632
|
|
| MD5 |
e67ccfcbc4af2337e6b37cf2af305d79
|
|
| BLAKE2b-256 |
a00382c2ee4382c2a1a844fea2fd50548b780bd55f20b44c76837831ed9b4d28
|
File details
Details for the file retry-0.7.0-py2-none-any.whl.
File metadata
- Download URL: retry-0.7.0-py2-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ed92155cb7fac7ca2787662d2df8a1b6f685e06e9b141b8d96fa42855648c45
|
|
| MD5 |
c57decb73309bcc8176ad83b6ac73c47
|
|
| BLAKE2b-256 |
7809b3f7745b6a8cdc777ae4e47ed283f8c0ce2d5b9b04946510e59dd95813cd
|