def retry_failure(reactor, function, expected=None, steps=None):
 if (steps is None):
  steps = repeat(0.1)
 steps = iter(steps)
 action = LOOP_UNTIL_ACTION(predicate=function)
 with action.context():
  d = DeferredContext(maybeDeferred(function))
 def loop(failure):
  if (expected and (not failure.check(*expected))):
   return failure
  try:
   interval = steps.next()
  except StopIteration:
   return failure
  d = deferLater(reactor, interval, action.run, function)
  d.addErrback(loop)
  return d
 d.addErrback(loop)
 def got_result(result):
  action.add_success_fields(result=result)
  return result
 d.addCallback(got_result)
 d.addActionFinish()
 return d.result

def retry_failure ( reactor , function , expected = None , steps = None ) : if ( steps is None ) : steps = repeat ( 0.1 ) steps = iter ( steps ) action = LOOP_UNTIL_ACTION ( predicate = function ) with action . context ( ) : d = DeferredContext ( maybeDeferred ( function ) ) def loop ( failure ) : if ( expected and ( not failure . check ( * expected ) ) ) : return failure try : interval = steps . next ( ) except StopIteration : return failure d = deferLater ( reactor , interval , action . run , function ) d . addErrback ( loop ) return d d . addErrback ( loop ) def got_result ( result ) : action . add_success_fields ( result = result ) return result d . addCallback ( got_result ) d . addActionFinish ( ) return d . result
retry function until it returns successfully .