def wait_until(timeout, retry_interval, func, value=True, op=operator.eq, *args, **kwargs):
    '\n    Wait until ``op(function(*args, **kwargs), value)`` is True or until timeout expires\n\n    * **timeout**  how long the function will try the function\n    * **retry_interval**  how long to wait between retries\n    * **func** the function that will be executed\n    * **value**  the value to be compared against (defaults to True)\n    * **op** the comparison function (defaults to equality)\\\n    * **args** optional arguments to be passed to func when called\n    * **kwargs** optional keyword arguments to be passed to func when called\n\n    Returns the return value of the function\n    If the operation times out then the return value of the the function\n    is in the \'function_value\' attribute of the raised exception.\n\n    e.g. ::\n\n        try:\n            # wait a maximum of 10.5 seconds for the\n            # the objects item_count() method to return 10\n            # in increments of .5 of a second\n            wait_until(10.5, .5, self.item_count, 10)\n        except TimeoutError as e:\n            print("timed out")\n    '
    start = timestamp()
    func_val = func(*args, **kwargs)
    while (not op(func_val, value)):
        time_left = (timeout - (timestamp() - start))
        if (time_left > 0):
            time.sleep(min(retry_interval, time_left))
            func_val = func(*args, **kwargs)
        else:
            err = TimeoutError('timed out')
            err.function_value = func_val
            raise err
    return func_val
Wait until ``op(function(*args, **kwargs), value)`` is True or until timeout expires

* **timeout**  how long the function will try the function
* **retry_interval**  how long to wait between retries
* **func** the function that will be executed
* **value**  the value to be compared against (defaults to True)
* **op** the comparison function (defaults to equality)\
* **args** optional arguments to be passed to func when called
* **kwargs** optional keyword arguments to be passed to func when called

Returns the return value of the function
If the operation times out then the return value of the the function
is in the 'function_value' attribute of the raised exception.

e.g. ::

    try:
        # wait a maximum of 10.5 seconds for the
        # the objects item_count() method to return 10
        # in increments of .5 of a second
        wait_until(10.5, .5, self.item_count, 10)
    except TimeoutError as e:
        print("timed out")
def wait_until(timeout, retry_interval, func, value=True, op=operator.eq, *args, **kwargs):
    '\n    Wait until ``op(function(*args, **kwargs), value)`` is True or until timeout expires\n\n    * **timeout**  how long the function will try the function\n    * **retry_interval**  how long to wait between retries\n    * **func** the function that will be executed\n    * **value**  the value to be compared against (defaults to True)\n    * **op** the comparison function (defaults to equality)\\\n    * **args** optional arguments to be passed to func when called\n    * **kwargs** optional keyword arguments to be passed to func when called\n\n    Returns the return value of the function\n    If the operation times out then the return value of the the function\n    is in the \'function_value\' attribute of the raised exception.\n\n    e.g. ::\n\n        try:\n            # wait a maximum of 10.5 seconds for the\n            # the objects item_count() method to return 10\n            # in increments of .5 of a second\n            wait_until(10.5, .5, self.item_count, 10)\n        except TimeoutError as e:\n            print("timed out")\n    '
    start = timestamp()
    func_val = func(*args, **kwargs)
    while (not op(func_val, value)):
        time_left = (timeout - (timestamp() - start))
        if (time_left > 0):
            time.sleep(min(retry_interval, time_left))
            func_val = func(*args, **kwargs)
        else:
            err = TimeoutError('timed out')
            err.function_value = func_val
            raise err
    return func_val