import time


def retry(func, max_tries = 16, timeout = 0.1):
    """Helper to retry functions and preserve exceptions, handy for network calls."""
    acm = 0
    while True:
        try:
            return func()
        except Exception as exception:        
            if acm > max_tries:
                raise exception
            time.sleep(timeout * (2 ** acm))
            acm += 1