Provides a decorator that automatically catches known transient exceptions that are common in the Ethereum/EVM ecosystem and reattempts to evaluate your decorated function
Project description
eth_retry
Stop transient errors from wasting your time!
eth_retry is a Python library that provides one decorator, eth_retry.auto_retry.
auto_retry will automatically catch known transient exceptions that are common in the Ethereum/EVM ecosystem and will reattempt to evaluate your decorated function up to os.environ['MAX_RETRIES'] (default: 10) times.
Supports both synchronous and asynchronous functions.
Covers many common transient errors in the EVM ecosystem, including:
- RPC timeouts
- Block explorer API rate-limiting
- Generic exceptions:
- ConnectionError
- HTTPError
- ReadTimeout
- TimeoutError
- eth-brownie specific errors:
- sqlite3.OperationalError: database is locked
Installation:
pip install eth_retry
or
pip install git+https://github.com/BobTheBuidler/eth_retry.git
Usage:
import eth_retry
@eth_retry.auto_retry
def some_function_that_errors_sometimes():
i = 0
am = 1
doing = 2
stuff = 3
return stuff
error_free_result = some_function_that_errors_sometimes()
Between attempts, eth_retry will time.sleep for a random period between os.environ['MIN_SLEEP_TIME'] (default: 10) and os.environ['MAX_SLEEP_TIME'] (default: 20) seconds. The period is randomized to help prevent repetitive rate-limiting issues with parallelism by staggering the retries.
On the nth retry, the sleep period is multiplied by n so that the target endpoint can cool off in case of rate-limiting.
After os.environ['MAX_RETRIES'] failures, eth_retry will raise the exception.
Environment:
# Minimum sleep time in seconds. Integer. Defaults to 10.
MIN_SLEEP_TIME=10
# Maximum sleep time in seconds. Integer. Defaults to 20.
MAX_SLEEP_TIME=20
# Maximum number of times to retry. Integer. Defaults to 10.
MAX_RETRIES=10
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 eth_retry-0.3.2.tar.gz.
File metadata
- Download URL: eth_retry-0.3.2.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.9.22 Linux/6.11.0-1012-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
043bcba0f1f88a94f20f8299170c8e12a44f2ab2c91ad53bd568d8a4f81c666b
|
|
| MD5 |
6ba634bb75b9901931ec610d093328a8
|
|
| BLAKE2b-256 |
48cb3bf6d438cac9bd7770964b64ab4e94e001ee758f57aad35a7424326e5725
|
File details
Details for the file eth_retry-0.3.2-py3-none-any.whl.
File metadata
- Download URL: eth_retry-0.3.2-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.9.22 Linux/6.11.0-1012-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89bf1265504af780873dd44428dec78354d99189ce20b8696a07e940ad0bb31b
|
|
| MD5 |
4686cfd4eaa1c6b4ed185430de92ff42
|
|
| BLAKE2b-256 |
76903557a6cf8a174b194fa951d8ace9d296e4584d0cc217aeab4a2d61418843
|