qcodes/tests/common.py
def retry_until_does_not_throw(
        exception_class_to_expect: Type[Exception] = AssertionError,
        tries: int = 5,
        delay: float = 0.1
) -> Callable[..., Any]:
    """
    Call the decorated function given number of times with given delay between
    the calls until it does not throw an exception of a given class.

    If the function throws an exception of a different class, it gets propagated
    outside (i.e. the function is not called anymore).

    Usage:
        >>  x = False  # let's assume that another thread has access to "x",
                       # and it is going to change "x" to "True" very soon
        >>  @retry_until_does_not_throw() ...
            def assert_x_is_true(): ...
                assert x, "x is still False..." ...
        >>  assert_x_is_true()  # depending on the settings of
                                # "retry_until_does_not_throw", it will keep
                                # calling the function (with breaks in between)
                                # until either it does not throw or
                                # the number of tries is exceeded.

    Args:
        exception_class_to_expect
            Only in case of this exception the function will be called again
        tries
            Number of times to retry calling the function before giving up
        delay
            Delay between retries of the function call, in seconds

    Returns:
        A callable that runs the decorated function until it does not throw
        a given exception
    """
    def retry_until_passes_decorator(func: Callable[..., Any]):

        @wraps(func)
        def func_retry(*args, **kwargs):
            tries_left = tries - 1
            while tries_left > 0:
                try:
                    return func(*args, **kwargs)
                except exception_class_to_expect:
                    tries_left -= 1
                    sleep(delay)
            # the very last attempt to call the function is outside
            # the "try-except" clause, so that the exception can propagate
            # up the call stack
            return func(*args, **kwargs)

        return func_retry

    return retry_until_passes_decorator

    Call the decorated function given number of times with given delay between
    the calls until it does not throw an exception of a given class.

    If the function throws an exception of a different class, it gets propagated
    outside (i.e. the function is not called anymore).

    Usage:
        >>  x = False  # let's assume that another thread has access to "x",
                       # and it is going to change "x" to "True" very soon
        >>  @retry_until_does_not_throw() ...
            def assert_x_is_true(): ...
                assert x, "x is still False..." ...
        >>  assert_x_is_true()  # depending on the settings of
                                # "retry_until_does_not_throw", it will keep
                                # calling the function (with breaks in between)
                                # until either it does not throw or
                                # the number of tries is exceeded.

    Args:
        exception_class_to_expect
            Only in case of this exception the function will be called again
        tries
            Number of times to retry calling the function before giving up
        delay
            Delay between retries of the function call, in seconds

    Returns:
        A callable that runs the decorated function until it does not throw
        a given exception
    
Call the decorated function given number of times with given delay between
the calls until it does not throw an exception of a given class.

If the function throws an exception of a different class, it gets propagated
outside .



exception_class_to_expect
Only in case of this exception the function will be called again
tries
Number of times to retry calling the function before giving up
delay
Delay between retries of the function call, in seconds

A callable that runs the decorated function until it does not throw
a given exception
Call the decorated function given number of times with given delay between the calls until it does not throw an exception of a given class . If the function throws an exception of a different class it gets propagated outside . exception_class_to_expect Only in case of this exception the function will be called again tries Number of times to retry calling the function before giving up delay Delay between retries of the function call in seconds A callable that runs the decorated function until it does not throw a given exception
def retry_until_does_not_throw(
        exception_class_to_expect: Type[Exception] = AssertionError,
        tries: int = 5,
        delay: float = 0.1
) -> Callable[..., Any]:
    def retry_until_passes_decorator(func: Callable[..., Any]):
        @wraps(func)
        def func_retry(*args, **kwargs):
            tries_left = tries - 1
            while tries_left > 0:
                try:
                    return func(*args, **kwargs)
                except exception_class_to_expect:
                    tries_left -= 1
                    sleep(delay)
            return func(*args, **kwargs)
        return func_retry
    return retry_until_passes_decorator
def retry_until_does_not_throw ( exception_class_to_expect : Type [ Exception ] = AssertionError , tries : int = 5 , delay : float = 0.1 ) -> Callable [ ... , Any ] : def retry_until_passes_decorator ( func : Callable [ ... , Any ] ) : @ wraps ( func ) def func_retry ( * args , ** kwargs ) : tries_left = tries - 1 while tries_left > 0 : try : return func ( * args , ** kwargs ) except exception_class_to_expect : tries_left -= 1 sleep ( delay ) return func ( * args , ** kwargs ) return func_retry return retry_until_passes_decorator
Call the decorated function given number of times with given delay between
the calls until it does not throw an exception of a given class.
Call the decorated function given number of times with given delay between the calls until it does not throw an exception of a given class .
"""
    Call the decorated function given number of times with given delay between
    the calls until it does not throw an exception of a given class.

    If the function throws an exception of a different class, it gets propagated
    outside (i.e. the function is not called anymore).

    Usage:
        >>  x = False  # let's assume that another thread has access to "x",
                       # and it is going to change "x" to "True" very soon
        >>  @retry_until_does_not_throw() ...
            def assert_x_is_true(): ...
                assert x, "x is still False..." ...
        >>  assert_x_is_true()  # depending on the settings of
                                # "retry_until_does_not_throw", it will keep
                                # calling the function (with breaks in between)
                                # until either it does not throw or
                                # the number of tries is exceeded.

    Args:
        exception_class_to_expect
            Only in case of this exception the function will be called again
        tries
            Number of times to retry calling the function before giving up
        delay
            Delay between retries of the function call, in seconds

    Returns:
        A callable that runs the decorated function until it does not throw
        a given exception
    """ # the very last attempt to call the function is outside # the "try-except" clause, so that the exception can propagate # up the call stack
exception_class_to_expect
Type[Exception]
tries
int
delay
float