code: def wait_for(self,
                 condition,
                 interval = DEFAULT_WAIT_INTERVAL,
                 timeout  = DEFAULT_WAIT_TIMEOUT):
      
  
      start = time.time()
  
      # at least execute the check once!
      while True:
        res = condition()
        if res:
          return res
  
        # timeout?
        if time.time() - start > timeout:
          break
  
        # wait a bit
        time.sleep(interval)
  
      # timeout occured!
      raise WaitTimeoutError("wait_for timed out")
docs: Wait until a condition holds by checking it in regular intervals.
      Raises ``WaitTimeoutError`` on timeout.