def _call_with_retry(max_attempts):
 def wrapper(f):
  def func_wrapper(*args, **kwargs):
   action = ('%(func)s' % {'func': getattr(f, '__name__', f)})
   for attempt in range(1, (max_attempts + 1)):
    try:
     return f(*args, **kwargs)
    except oslo_messaging.MessagingException:
     with excutils.save_and_reraise_exception(reraise=False) as ctxt:
      LOG.warning(_LW('Failed to execute %(action)s. %(attempt)d out of %(max_attempts)d'), {'attempt': attempt, 'max_attempts': max_attempts, 'action': action})
      if (attempt == max_attempts):
       ctxt.reraise = True
  return func_wrapper
 return wrapper

def _call_with_retry ( max_attempts ) : def wrapper ( f ) : def func_wrapper ( * args , ** kwargs ) : action = ( '%(func)s' % { 'func' : getattr ( f , '__name__' , f ) } ) for attempt in range ( 1 , ( max_attempts + 1 ) ) : try : return f ( * args , ** kwargs ) except oslo_messaging . MessagingException : with excutils . save_and_reraise_exception ( reraise = False ) as ctxt : LOG . warning ( _LW ( 'Failed to execute %(action)s. %(attempt)d out of %(max_attempts)d' ) , { 'attempt' : attempt , 'max_attempts' : max_attempts , 'action' : action } ) if ( attempt == max_attempts ) : ctxt . reraise = True return func_wrapper return wrapper
a wrapper to retry a function using rpc call in case of messagingexception .