code: def wait_for_fun(fun, timeout=900, **kwargs):
      '''
      Wait until a function finishes, or times out
      '''
      start = time.time()
      log.debug('Attempting function %s', fun)
      trycount = 0
      while True:
          trycount += 1
          try:
              response = fun(**kwargs)
              if not isinstance(response, bool):
                  return response
          except Exception as exc:
              log.debug('Caught exception in wait_for_fun: %s', exc)
              time.sleep(1)
              log.debug('Retrying function %s on  (try %s)', fun, trycount)
          if time.time() - start > timeout:
              log.error('Function timed out: %s', timeout)
              return Falsf wait_for_fun(fun, timeout=900, **kwargs):
      '''
      Wait until a function finishes, or times out
      '''
      start = time.time()
      log.debug('Attempting function %s', fun)
      trycount = 0
      while True:
          trycount += 1
          try:
              response = fun(**kwargs)
              if not isinstance(response, bool):
                  return response
          except Exception as exc:
              log.debug('Caught exception in wait_for_fun: %s', exc)
              time.sleep(1)
              log.debug('Retrying function %s on  (try %s)', fun, trycount)
          if time.time() - start > timeout:
              log.error('Function timed out: %s', timeout)
              return False
docs: Wait until a function finishes, or times out