def retries(max_tries, delay=1, backoff=1.1, exceptions=(Exception, HttpError, socket_error), hook=gme_exc_handler):
    """Function decorator implementing retrying logic.

    delay: Sleep this many seconds * backoff * try number after failure
    backoff: Multiply delay by this factor after each failure
    exceptions: A tuple of exception classes; default (Exception,)
    hook: A function with the signature myhook(tries_remaining, exception);
          default None

    The decorator will call the function up to max_tries times if it raises
    an exception.

    By default it catches instances of the Exception class and subclasses.
    This will recover after all but the most fatal errors. You may specify a
    custom tuple of exception classes with the 'exceptions' argument; the
    function will only be retried if it raises one of the specified
    exceptions.

    Additionally you may specify a hook function which will be called prior
    to retrying with the number of remaining tries and the exception instance;
    see given example. This is primarily intended to give the opportunity to
    log the failure. Hook is not called after failure if no retries remain.
    """
    def dec(func):
        def f2(*args, **kwargs):
            mydelay = delay
            tries = range(max_tries)
            tries.reverse()
            for tries_remaining in tries:
                try:
                   return func(*args, **kwargs)
                except exceptions as e:
                    if 0 > tries_remaining:
                        if hook is not None:
                            hook(tries_remaining, e, mydelay, args)
                        sleep(mydelay)
                        mydelay = mydelay * backoff
                    else:
                        raise e
                else:
                    break
        return f2
    return dec
dataset/ETHPy150Open keithmoss/Hodor/hodor/retries.py/retries/swapped operands of `>`