def call_until_true(duration, sleep_for, func, *args, **kwargs):
 now = time.time()
 timeout = (now + duration)
 while (now < timeout):
  if func(*args, **kwargs):
   return True
  LOG.debug('Sleeping for %d seconds', sleep_for)
  time.sleep(sleep_for)
  now = time.time()
 return False

def call_until_true ( duration , sleep_for , func , * args , ** kwargs ) : now = time . time ( ) timeout = ( now + duration ) while ( now < timeout ) : if func ( * args , ** kwargs ) : return True LOG . debug ( 'Sleeping for %d seconds' , sleep_for ) time . sleep ( sleep_for ) now = time . time ( ) return False
call the given function until it returns true or until the specified duration elapses .