def LoopUntilTimeoutOrValid(timeout_s, function, validation_fn, sleep_s=1):  # pylint: disable=invalid-name
  if timeout_s is None or not hasattr(timeout_s, 'HasExpired'):
    timeout_s = PolledTimeout(timeout_s)

  while True:
    # Calls the function at least once
    result = function()
    if validation_fn(result) or timeout_s.HasExpired():
      return result
    time.sleep(sleep_s)
Loops until the specified function returns valid or a timeout is reached.
dataset/ETHPy150Open google/openhtf/openhtf/util/timeouts.py/LoopUntilTimeoutOrValid