Skip to main content

Helper for retrying code when exception occur

Project description

Retry Helper

Helper tool fro retrying code when soem exceptions occur

Usage

RetryManager

Retry manager is context manager for retrying block of code. In fact its double layer context manager in first context you will create context manager and use while retry object is true. And the run you code in context of retry.attempt.

  • max_attempts - maximum count of attempts, default 1
  • wait_seconds - How many second it should wait before next retry, default 0
  • exceptions - exception class or tuple of exceptions classes which cause retry, if None all exceptions cause retry default None
  • reset_func - function to be run before each retry (it is not call on first try)
with RetryManager(max_attempts=20, wait_seconds=1, exceptions=(TypeError,KeyError)) as retry:
while retry:
    with retry.attempt:
        # code raising exception if fail

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

retry_helper-0.0.4.tar.gz (3.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page