This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

VERSION: 0.1.8

Introduction

Function decorator that helps to retry the function under certain criteria.

This package contains the retry decorator and a bunch of configuration parameters for this decorator.

Tested on python 2.7 and python 3.4.

For quick start, check the tutorial section of this page. Check [test_retryz.py](test/test_retryz.py) for detail examples.

Installation

pip install retryz

Tutorial

  • Retry if ValueError is caught.
@retry(on_error=ValueError)
def my_func():
    ...
  • Retry if ValueError or TypeError is caught.
@retry(on_error=lambda e: isinstance(e, (ValueError, TypeError)))
def my_func():
    ...
  • Retry until TypeError is caught.
@retry(on_error=lambda e: not isinstance(e, TypeError))
def my_func():
    ...
  • Retry until TypeError or AttributeError is caught.
@retry(on_error=lambda e: not isinstance(e, (TypeError, AttributeError)))
def my_func():
    ...
  • When on_error is a callback, it will retry until on_error returns False. Note that callback takes one parameter which is the error instance raised by the decorated function.
def _error_callback(self, ex):
    assert_that(ex, instance_of(TypeError))
    return self.call_count != 4

@retry(on_error=_error_callback)
def error_call_back(self):
    ...
  • Retry if returns certain value.
@retry(on_return=True)
def my_func(self):
    ...
  • Retry if return value in the list.
@retry(on_return=lambda x: x in (1, 2, 3, 4, 5))
def my_func(self):
    ...
  • Retry until certain value is returned.
@retry(on_return=lambda x: x != 4)
def my_func(self):
    ...
  • Retry until any of the value is returned.
@retry(on_return=lambda x: x not in [3, 4])
def my_func(self):
    ...
  • When on_return is a callback, it will retry until on_return returns False. Note that callback takes one parameter which is the return value of the decorated function.
def _return_callback(ret):
    return 4 + ret < 7

@retry(on_return=_return_callback)
def my_func(self):
    ...
  • Retry until timeout (in seconds)
@retry(timeout=0.1)
def my_func():
    ...
  • Retry maximum X times.
@retry(limit=3)
def my_func():
    ...

# or you could specify a callback
@retry(limit=lambda: 4)
def my_func_x():
    ...
  • Wait X seconds between each retry.
@retry(wait=0.1, timeout=0.3)
def my_func():
    ...
  • When wait is a callback, it will wait for the amount of seconds returned by the callback. The callback takes one parameter which is the current count of retry.
def _wait_callback(self, tried):
    return 2 ** tried

@retry(wait=_wait_callback, timeout=0.1)
def my_func():
    ...
  • on_retry could be used to specify a callback. This callback is a function with no parameter. It will be invoked before each retry. Here is a typical usage.
def do_login():
    # login if not
    ...

@retry(on_retry=do_login, limit=2)
def requests(resource_id):
    ...
  • retry could also be called in a functional style. Note that the return value is a function. If you want to call it, you need to add an extra ().
def foo():
    ...

retry(foo, limit=3, timeout=5)()

To file issue, please visit:

https://github.com/jealous/retryz

Contact author:

Release History

Release History

0.1.8

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.7

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
retryz-0.1.8.zip (15.6 kB) Copy SHA256 Checksum SHA256 Source Aug 2, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting