parameters: (on_failure)
return_statement: return decorator
docstring: A decorator that handles device failures for per-device functions.
  
    This calls on_failure in the event of a failure.
  
    Args:
      f: the function being decorated. The function must take at least one
        argument, and that argument must be the device.
      on_failure: A binary function to call on failure.
docstring_summary: A decorator that handles device failures for per-device functions.
docstring_tokens: A decorator that handles device failures for per - device functions .
function: def handle_shard_failures_with(on_failure):
    """A decorator that handles device failures for per-device functions.
  
    This calls on_failure in the event of a failure.
  
    Args:
      f: the function being decorated. The function must take at least one
        argument, and that argument must be the device.
      on_failure: A binary function to call on failure.
    """
    def decorator(f):
      @functools.wraps(f)
      def wrapper(dev, *args, **kwargs):
        try:
          return f(dev, *args, **kwargs)
        except device_errors.CommandTimeoutError:
          logging.exception('Shard timed out: %s(%s)', f.__name__, str(dev))
        except device_errors.DeviceUnreachableError:
          logging.exception('Shard died: %s(%s)', f.__name__, str(dev))
        except base_error.BaseError:
          logging.exception('Shard failed: %s(%s)', f.__name__, str(dev))
        except SystemExit:
          logging.exception('Shard killed: %s(%s)', f.__name__, str(dev))
          raise
        if on_failure:
          on_failure(dev, f.__name__)
        return None
  
      return wrapper
  
    return decorator
function_tokens: def handle_shard_failures_with ( on_failure ) : def decorator ( f ) : @ functools . wraps ( f ) def wrapper ( dev , * args , * * kwargs ) : try : return f ( dev , * args , * * kwargs ) except device_errors . CommandTimeoutError : logging . exception ( 'Shard timed out: %s(%s)' , f . __name__ , str ( dev ) ) except device_errors . DeviceUnreachableError : logging . exception ( 'Shard died: %s(%s)' , f . __name__ , str ( dev ) ) except base_error . BaseError : logging . exception ( 'Shard failed: %s(%s)' , f . __name__ , str ( dev ) ) except SystemExit : logging . exception ( 'Shard killed: %s(%s)' , f . __name__ , str ( dev ) ) raise if on_failure : on_failure ( dev , f . __name__ ) return None return wrapper return decorator