def exponential_retrier(func_to_retry, exception_filter=(lambda *args, **kw: True), retry_min_wait_ms=500, max_retries=5):
 sleep_time = retry_min_wait_ms
 num_retried = 0
 while True:
  try:
   return func_to_retry()
  except StopIteration:
   raise
  except Exception as e:
   g.log.exception(('%d number retried' % num_retried))
   num_retried += 1
   if ((num_retried > max_retries) or (not exception_filter(e))):
    raise
   time.sleep((sleep_time / 1000.0))
   sleep_time *= 2

def exponential_retrier ( func_to_retry , exception_filter = ( lambda * args , ** kw : True ) , retry_min_wait_ms = 500 , max_retries = 5 ) : sleep_time = retry_min_wait_ms num_retried = 0 while True : try : return func_to_retry ( ) except StopIteration : raise except Exception as e : g . log . exception ( ( '%d number retried' % num_retried ) ) num_retried += 1 if ( ( num_retried > max_retries ) or ( not exception_filter ( e ) ) ) : raise time . sleep ( ( sleep_time / 1000.0 ) ) sleep_time *= 2
call func_to_retry and return its results .