def _try_until_true(func, max_tries=5, sleep_time=0.5):
 for _ in xrange(0, max_tries):
  if func():
   return True
  else:
   time.sleep(sleep_time)
 return False

def _try_until_true ( func , max_tries = 5 , sleep_time = 0.5 ) : for _ in xrange ( 0 , max_tries ) : if func ( ) : return True else : time . sleep ( sleep_time ) return False
calls func up to max_tries times until it returns true .