import time


def run_until(timeout, fun):
    """ run function until it returns True or timeout seconds passes """
    start = time.time()
    while True:
        if fun():
            return True
        if time.time() > start + timeout:
            break
        time.sleep(1)
    return False