A tiny retry helper for synchronous Python code.
Project description
tiny-retry v0.2.1
tiny-retry is a tiny package for retrying (synchronous) Python functions when they raise exceptions, designed to keep things light and simple.
Installation
pip install tiny-retry-gw
Usage
from tiny_retry import retry, retry_infinite
def foo():
# Replace this code with something that can raise the exception(s) you want to retry on.
...
# This will try foo() 6 times, with a delay of 3.1 seconds between retries, and it will only retry when ConnectionError is raised.
result = retry(foo, tries=6, delay=3.10, exceptions=(ConnectionError,))
# This will try foo() infinitely, with a delay of 3.1 seconds between retries, and it will only retry when ConnectionError is raised.
result = retry_infinite(foo, delay=3.10, exceptions=(ConnectionError,))
Parameters
func: function to call.tries: how many times to attempt the function (must be >= 1).delay: delay in seconds between retries.exceptions: a tuple of exceptions that should trigger another attempt.*args,**kwargs: optional positional and keyword arguments to be passed intofunc.
If all attempts fail, retry reraises the last exception so the caller can handle or log it.
Notes
- retry_infinite does not take
triesas a parameter.
Development
Run the simple tests from the repo root:
python -m pytest
License
Apache 2.0 © Gatoware
6310
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
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 tiny_retry_gw-0.2.1.tar.gz.
File metadata
- Download URL: tiny_retry_gw-0.2.1.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bbae6aa808ad347aa257a5983fe4731af43d320d4d0dfe6775e989f5a919529
|
|
| MD5 |
156dc083e2cbc232e949eca1f89ffcd5
|
|
| BLAKE2b-256 |
2e89fc03255ae6751e9a85302fa9bce8018135d2fc38e2c5bf398d580f2cf5a0
|
File details
Details for the file tiny_retry_gw-0.2.1-py3-none-any.whl.
File metadata
- Download URL: tiny_retry_gw-0.2.1-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d4823911491b182eab3c1b25d95c3deaf0c9856ca62f4e43bf1355fa9c8410e
|
|
| MD5 |
177adfd81a3e85b5ba362db159d7ceac
|
|
| BLAKE2b-256 |
7a3e798cb91f9f4e531656a81d79a0bfee4d082a2e1c7ac18075755d9e85fa31
|