import time


def wait_for( func, max_seconds=10, pause=1 ):
    """ def wait_for
        Wait for up to max_seconds for func to return True
        If func returns True within time alloted, return True
        Otherwise, return False
        func must return a boolean value (others might work, but behavior is undefined)
    """
    rv = False
    start = time.time()
    diff = 0
    while rv != True and diff < max_seconds:
        rv = func()
        if rv is not True and rv is not False:
            raise UserWarning( "func '{0}' did not return a boolean value".format( func ) )
        time.sleep( pause )
        diff = time.time() - start
    return rv