Skip to main content

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

eth_retry-0.3.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eth_retry-0.3.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file eth_retry-0.3.0.tar.gz.

File metadata

  • Download URL: eth_retry-0.3.0.tar.gz
  • Upload date:
  • Size: 5.0 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

Hashes for eth_retry-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6c6b2d5b853f54c80910d34bb4d83a0a334986e3d1da57d295cc88d8ffe09a88
MD5 0384226ef3cabccdac07d1c9215452bb
BLAKE2b-256 c535f20e00db2085a38adf9180bb53cc32b60a3a8802609eac70f31bdcb71639

See more details on using hashes here.

File details

Details for the file eth_retry-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: eth_retry-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 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

Hashes for eth_retry-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a2fb6837f93e44c821f04b5caf75e7ff7ad038d0d2478637fd5cc84529ed01f
MD5 47f8538ae44b8a92c19b96ea1f67fbd6
BLAKE2b-256 575e65e35f92f79ad2a9d8bd8c01304c28dc2fb684ab0e280e5d3cda63795e27

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