import time


def wait_until_not_raised(condition, delay, max_attempts):
    """
    Executes a function at regular intervals while the condition
    doesn't raise an exception and the amount of attempts < maxAttempts.
    :param condition: a function
    :param delay: the delay in second
    :param max_attempts: the maximum number of attemps. So the timeout
                         of this function will be delay*max_attempts
    """
    def wrapped_condition():
        try:
            condition()
        except:
            return False

        return True

    attempt = 0
    while attempt < (max_attempts-1):
        attempt += 1
        if wrapped_condition():
            return

        time.sleep(delay)

    # last attempt, let the exception raise
    condition()