def try_multiple(ntrials, exception, base, f, *args, **kwargs):
    'Call f multiple times making exponentially growing delay between the calls'
    for trial in range(1, (ntrials + 1)):
        try:
            return f(*args, **kwargs)
        except exception as exc:
            if (trial == ntrials):
                raise
            t = (base ** trial)
            lgr.warning('Caught %s on trial #%d. Sleeping %f and retrying', CapturedException(exc), trial, t)
            sleep(t)
Call f multiple times making exponentially growing delay between the calls
def try_multiple(ntrials, exception, base, f, *args, **kwargs):
    
    for trial in range(1, (ntrials + 1)):
        try:
            return f(*args, **kwargs)
        except exception as exc:
            if (trial == ntrials):
                raise
            t = (base ** trial)
            lgr.warning('Caught %s on trial #%d. Sleeping %f and retrying', CapturedException(exc), trial, t)
            sleep(t)