def __wrap_methods_with_call_and_maybe_retry(self, name):

        def call_and_maybe_retry(*args, **kwargs):
            n = len(self.__alternatives)

            for i in range(n):
                index = (self.__start_index + i) % n
                alternative = self.__alternatives[index]

                try:
                    result = getattr(alternative, name)(*args, **kwargs)
                    # this one works, start here next time!
                    self.__start_index = index
                    return result
                except Exception as ex:
                    # that one didn't work out, retry if we can
                    if i < n - 1 and self.__retry_if(ex):
                        log.info('%r.%s() raised %r, trying next alternative'
                                 % (alternative, name, ex))
                    else:
                        raise

        # pretend to be the original function
        f = getattr(self.__alternatives[self.__start_index], name)
        return wraps(f)(call_and_maybe_retry)
Wrap calls to name().
dataset/ETHPy150Open Yelp/mrjob/mrjob/retry.py/RetryGoRound.__wrap_methods_with_call_and_maybe_retry