Retry decorator for both synchronous and asynchronous functions.
Project description
Retry decorator
Usage
#!/usr/bin/env python3
import sys
from retry_decorator import retry, RetryHandler
def throw_err(msg):
print('hello', file=sys.stderr)
raise Exception('throwing err for {}'.format(msg))
def callback(msg):
print('callback called: {}'.format(msg), file=sys.stderr)
@retry(Exception, tries=3, timeout_secs=0.1)
def test_retry_via_decorator():
throw_err('retry-via-deco')
def test_retry_via_instance():
cbe = {
Exception: lambda: callback('retry-via-instance')
}
retry(tries=3, callback_by_exception=cbe)(throw_err)('retry-via-instance')
def test_retry_via_instance2():
cbe = {
Exception: lambda: callback('retry-via-instance2')
}
RetryHandler(tries=3, callback_by_exception=cbe)(throw_err, 'retry-via-instance2')
if __name__ == '__main__':
try:
test_retry_via_decorator()
except Exception as e:
print('Received the last exception')
try:
test_retry_via_instance()
except Exception as e:
print('Received the last exception')
try:
test_retry_via_instance2()
except Exception as e:
print('Received the last exception')
Building
python3 -m pip install --user --upgrade build
python3 -m build
Contribute
Best contribute to upstream project, but it might be abandoned. Also its defaults will be different from this project, unless PR21 (which is the reason for this fork) is accepted.
So... it's up to you which project you raise your PR against, but contributions are welcome.
Credits
This project is largely influenced & sourced from https://github.com/pnpnpn/retry-decorator and https://gitlab.com/ramil.minnigaliev/the-retry
See also
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
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
File details
Details for the file retry_deco-0.0.3.tar.gz.
File metadata
- Download URL: retry_deco-0.0.3.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
138d2b89615bd717a070534efbb4b86067bf0e11e3311e80800ab81c939875d7
|
|
| MD5 |
991557b6d69d6b93d60daf09d294442d
|
|
| BLAKE2b-256 |
ec45b64ae5425dcbc057ef5d92396e464af42551cd45f6ee7cd643693969d5c0
|
File details
Details for the file retry_deco-0.0.3-py3-none-any.whl.
File metadata
- Download URL: retry_deco-0.0.3-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c57789a987bb17edf365c078ef0b28eecb1e20a5d27a53e295de05515b4b9fd7
|
|
| MD5 |
f0577d7a9c44234b6513fdc68321eafb
|
|
| BLAKE2b-256 |
707b4638223f26c1824a59a5e82f49513448c904b2e4e3349f22566893f77728
|