retry_decorator/retry_decorator.py
def _deco_retry(f, exc=Exception, tries=10, timeout_secs=1.0, logger=None, callback_by_exception=None):
    """
    Common function logic for the internal retry flows.
    :param f:
    :param exc:
    :param tries:
    :param timeout_secs:
    :param logger:
    :param callback_by_exception:
    :return:
    """
    def f_retry(*args, **kwargs):
        mtries, mdelay = tries, timeout_secs
        run_one_last_time = True
        while mtries > 1:
            try:
                return f(*args, **kwargs)
            except exc as e:
                # check if this exception is something the caller wants special handling for
                callback_errors = callback_by_exception or {}
                for error_type in callback_errors:
                    if isinstance(e, error_type):
                        callback_logic = callback_by_exception[error_type]
                        should_break_out = run_one_last_time = False
                        if isinstance(callback_logic, (list, tuple)):
                            callback_logic, should_break_out = callback_logic
                            if isinstance(should_break_out, (list, tuple)):
                                should_break_out, run_one_last_time = should_break_out
                        callback_logic()
                        if should_break_out:  # caller requests we stop handling this exception
                            break
                half_interval = mdelay * 0.10  # interval size
                actual_delay = random.uniform(mdelay - half_interval, mdelay + half_interval)
                msg = "Retrying in %.2f seconds ..." % actual_delay
                logging_object = logger or logging
                logging_object.exception(msg)
                time.sleep(actual_delay)
                mtries -= 1
                mdelay *= 2
        if run_one_last_time:  # one exception may be all the caller wanted in certain cases
            return f(*args, **kwargs)

    return f_retry

    Common function logic for the internal retry flows.
    :param f:
    :param exc:
    :param tries:
    :param timeout_secs:
    :param logger:
    :param callback_by_exception:
    :return:
    
Common function logic for the internal retry flows.
Common function logic for the internal retry flows .
def _deco_retry(f, exc=Exception, tries=10, timeout_secs=1.0, logger=None, callback_by_exception=None):
    def f_retry(*args, **kwargs):
        mtries, mdelay = tries, timeout_secs
        run_one_last_time = True
        while mtries > 1:
            try:
                return f(*args, **kwargs)
            except exc as e:
                callback_errors = callback_by_exception or {}
                for error_type in callback_errors:
                    if isinstance(e, error_type):
                        callback_logic = callback_by_exception[error_type]
                        should_break_out = run_one_last_time = False
                        if isinstance(callback_logic, (list, tuple)):
                            callback_logic, should_break_out = callback_logic
                            if isinstance(should_break_out, (list, tuple)):
                                should_break_out, run_one_last_time = should_break_out
                        callback_logic()
                        if should_break_out:  
                            break
                half_interval = mdelay * 0.10  
                actual_delay = random.uniform(mdelay - half_interval, mdelay + half_interval)
                msg = "Retrying in %.2f seconds ..." % actual_delay
                logging_object = logger or logging
                logging_object.exception(msg)
                time.sleep(actual_delay)
                mtries -= 1
                mdelay *= 2
        if run_one_last_time:  
            return f(*args, **kwargs)
    return f_retry
def _deco_retry ( f , exc = Exception , tries = 10 , timeout_secs = 1.0 , logger = None , callback_by_exception = None ) : def f_retry ( * args , ** kwargs ) : mtries , mdelay = tries , timeout_secs run_one_last_time = True while mtries > 1 : try : return f ( * args , ** kwargs ) except exc as e : callback_errors = callback_by_exception or { } for error_type in callback_errors : if isinstance ( e , error_type ) : callback_logic = callback_by_exception [ error_type ] should_break_out = run_one_last_time = False if isinstance ( callback_logic , ( list , tuple ) ) : callback_logic , should_break_out = callback_logic if isinstance ( should_break_out , ( list , tuple ) ) : should_break_out , run_one_last_time = should_break_out callback_logic ( ) if should_break_out : break half_interval = mdelay * 0.10 actual_delay = random . uniform ( mdelay - half_interval , mdelay + half_interval ) msg = "Retrying in %.2f seconds ..." % actual_delay logging_object = logger or logging logging_object . exception ( msg ) time . sleep ( actual_delay ) mtries -= 1 mdelay *= 2 if run_one_last_time : return f ( * args , ** kwargs ) return f_retry
Common function logic for the internal retry flows.
Common function logic for the internal retry flows .
"""
    Common function logic for the internal retry flows.
    :param f:
    :param exc:
    :param tries:
    :param timeout_secs:
    :param logger:
    :param callback_by_exception:
    :return:
    """ # check if this exception is something the caller wants special handling for # caller requests we stop handling this exception # interval size # one exception may be all the caller wanted in certain cases
None
f
None
exc
None
tries
None
timeout_secs
None
logger
None
callback_by_exception
None