Welcome to retry.it’s documentation!


A simple python module to add a retry function decorator

exception retry.MaximumRetriesExceeded
exception retry.MaximumTimeoutExceeded
retry.retry(exceptions=(<type 'exceptions.Exception'>, ), interval=0, max_retries=10, success=None, timeout=-1)

Decorator to retry a function ‘max_retries’ amount of times

  • exceptions (tuple) – Exceptions to be caught for retries
  • interval (int) – Interval between retries in seconds
  • max_retries (int) – Maximum number of retries to have, if set to -1 the decorator will loop forever
  • success (function) – Function to indicate success criteria
  • timeout (int) – Timeout interval in seconds, if -1 will retry forever
  • MaximumRetriesExceeded – Maximum number of retries hit without reaching the success criteria
  • TypeError – Both exceptions and success were left None causing the decorator to have no valid exit criteria.

Use it to decorate a function!

from retry import retry

@retry(exceptions=(ArithmeticError,), success=lambda x: x > 0)
def foo(bar):
    if bar < 0:
        raise ArithmeticError('testing this')
    return bar
# Should return 5
# Should raise ArithmeticError
# Should raise MaximumRetriesExceeded

Indices and tables