def _poll_until_success_returning_result(should_retry, steps, sleep, function, args, kwargs):
 saved_result = [None]
 def pollable():
  Message.new(message_type=_TRY_RETRYING).write()
  try:
   result = function(*args, **kwargs)
  except Exception as e:
   saved_result[0] = exc_info()
   should_retry(*saved_result[0])
   Message.new(message_type=_TRY_FAILURE, exception=str(e)).write()
   return False
  else:
   Message.new(message_type=_TRY_SUCCESS, result=result).write()
   saved_result[0] = result
   return True
 try:
  poll_until(pollable, (step.total_seconds() for step in steps), sleep=sleep)
 except LoopExceeded:
  thing = saved_result.pop()
  try:
   raise thing[0], thing[1], thing[2]
  finally:
   del thing
 else:
  return saved_result[0]

def _poll_until_success_returning_result ( should_retry , steps , sleep , function , args , kwargs ) : saved_result = [ None ] def pollable ( ) : Message . new ( message_type = _TRY_RETRYING ) . write ( ) try : result = function ( * args , ** kwargs ) except Exception as e : saved_result [ 0 ] = exc_info ( ) should_retry ( * saved_result [ 0 ] ) Message . new ( message_type = _TRY_FAILURE , exception = str ( e ) ) . write ( ) return False else : Message . new ( message_type = _TRY_SUCCESS , result = result ) . write ( ) saved_result [ 0 ] = result return True try : poll_until ( pollable , ( step . total_seconds ( ) for step in steps ) , sleep = sleep ) except LoopExceeded : thing = saved_result . pop ( ) try : raise thing [ 0 ] , thing [ 1 ] , thing [ 2 ] finally : del thing else : return saved_result [ 0 ]
call a function until it does not raise an exception or should_retry says it shouldnt be tried anymore .