Sha256: 973028a5036baea81a6b6ca8847f3a0f046f144f42b7ede67b7fd9a9dd43106c

Contents?: true

Size: 1.53 KB

Versions: 53

Compression:

Stored size: 1.53 KB

Contents

import time
from functools import wraps


def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logger=None):
    """Retry calling the decorated function using an exponential backoff.

    http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
    original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry

    :param ExceptionToCheck: the exception to check. may be a tuple of
        exceptions to check
    :type ExceptionToCheck: Exception or tuple
    :param tries: number of times to try (not retry) before giving up
    :type tries: int
    :param delay: initial delay between retries in seconds
    :type delay: int
    :param backoff: backoff multiplier e.g. value of 2 will double the delay
        each retry
    :type backoff: int
    :param logger: logger to use. If None, print
    :type logger: logging.Logger instance
    """
    def deco_retry(f):

        @wraps(f)
        def f_retry(*args, **kwargs):
            mtries, mdelay = tries, delay
            while mtries > 1:
                try:
                    return f(*args, **kwargs)
                except ExceptionToCheck, e:
                    msg = "%s, Retrying in %d seconds..." % (str(e), mdelay)
                    if logger:
                        logger.warning(msg)
                    else:
                        print msg
                    time.sleep(mdelay)
                    mtries -= 1
                    mdelay *= backoff
            return f(*args, **kwargs)

        return f_retry  # true decorator

    return deco_retry

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
libv8-8.4.255.0.1 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-8.4.255.0 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-7.8.279.23.0beta1 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-7.4.288.28.0beta1 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-7.3.492.27.3beta1 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-7.3.492.27.1 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-7.3.492.27.0 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-7.3.492.27.0beta1 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-6.7.288.46.1 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-6.7.288.46.0 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-6.7.288.46.1beta0 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-6.3.292.48.1 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-6.3.292.48.0 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-6.3.292.48.0beta2 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-6.3.292.48.0beta1 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-6.2.414.42.1 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-6.2.414.42.0 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-6.2.414.42.0beta1 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-6.0.286.54.3 vendor/depot_tools/third_party/retry_decorator/decorators.py
libv8-6.0.286.54.2 vendor/depot_tools/third_party/retry_decorator/decorators.py