def wait_for_fun(fun, timeout=900, **kwargs):
 start = time.time()
 log.debug('Attempting function {0}'.format(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: {0}'.format(exc))
   time.sleep(1)
   log.debug('Retrying function {0} on  (try {1})'.format(fun, trycount))
  if ((time.time() - start) > timeout):
   log.error('Function timed out: {0}'.format(timeout))
   return False

def wait_for_fun ( fun , timeout = 900 , ** kwargs ) : start = time . time ( ) log . debug ( 'Attempting function {0}' . format ( 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: {0}' . format ( exc ) ) time . sleep ( 1 ) log . debug ( 'Retrying function {0} on  (try {1})' . format ( fun , trycount ) ) if ( ( time . time ( ) - start ) > timeout ) : log . error ( 'Function timed out: {0}' . format ( timeout ) ) return False
wait until a function finishes .