def wait_for(func, timeout=10, step=1, default=None, func_args=(), func_kwargs=None):
    if func_kwargs is None:
        func_kwargs = dict()
    max_time = time.time() + timeout
    # Time moves forward so we might not reenter the loop if we step too long
    step = min(step or 1, timeout) * BLUR_FACTOR

    ret = default
    while time.time() <= max_time:
        call_ret = func(*func_args, **func_kwargs)
        if call_ret:
            ret = call_ret
            break
        else:
            time.sleep(step)

            # Don't allow cases of over-stepping the timeout
            step = min(step, max_time - time.time()) * BLUR_FACTOR
    if time.time() > max_time:
        logging.warn("Exceeded waiting time (%s seconds) to exectute %s", timeout, func)
    return ret
Call `func` at regular intervals and Waits until the given function returns a truthy value
dataset/ETHPy150Open saltstack/salt/salt/utils/timeout.py/wait_for