Skip to main content

Python retry utility

Project description

Travis Test Status

A simple way to auto retry a funciton that has the possibility of raising an error. You can either call retry directly or decorate a function to get it to retry. Intelligent matching logic allows you to retry certain exception while raising other exceptions.

Using retry as a function:

from retrypy import retry, check
def dummy_func():
    print "dummy_func called..."
    raise Exception("House")

retry.call(
    dummy_func,
    times=2
)

dummy_func called...
dummy_func called...
Exception: House

# usign a check method
retry.call(
    dummy_func,
    check = check.message_equals("foobar")
)
dummy_func called...
Exception: House

Params:

func: The function you want to call.
args: Positional args to be passed to func
kwargs: keywords args to be passed to func
exceptions: an array of Exception types you want to retry on.
check: A function that excepts Exception and Count and
    returns true if the function should be retried.
times: number of times to try the function (default=5)
wait: number of seconds to wait between tries (default=0) or a function
    that accepts try_count and returns a number of seconds to wait

Or you can use it as a decorator:

@retry.decorate(Exception, times=2)
def dummy_func():
    print "dummy_func called..."
    raise Exception("House")
dummy_func()

dummy_func called...
dummy_func called...
Exception: House

# custom wait function
@retry.decorate(Exception, times=2, wait=lambda n: 2*n)
def dummy_func():
    print "dummy_func called..."
    raise Exception("House")
dummy_func()

dummy_func called...
dummy_func called...
Exception: House

Params:

positional_args: All position arguments must be Exception types, these
    are the only types of exceptions we will retry.
check: see retrypy.call
times: see retrypy.call
wait: see retrypy.call

Or you can use it to wrap a function and return a new callable

def dummy_func():
    print "dummy_func called..."
    raise Exception("House")

func = retry.wrap(
    dummy_func,
    times=2
)
func()

dummy_func called...
dummy_func called...
Exception: House

Params: See Docs for retry.call

Installation

>> pip install retrypy

License:

See LICENSE

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

retrypy-0.0.2.tar.gz (3.2 kB view details)

Uploaded Source

File details

Details for the file retrypy-0.0.2.tar.gz.

File metadata

  • Download URL: retrypy-0.0.2.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for retrypy-0.0.2.tar.gz
Algorithm Hash digest
SHA256 dee6bcfb15ffdf95dba371f795b9999bb7146374b782d040e6d711ee534d7b60
MD5 dbca9b978b3710396e3562398969c0f7
BLAKE2b-256 54517ffc43b8a93c631b5bf63d771f4dc4295c03ce8849445d41d3ea7570d941

See more details on using hashes here.

Supported by

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