def ApplyPluginsToBatch(self, hunt_urn, plugins, batch, batch_index):
    exceptions_by_plugin = {}
    for plugin_def, plugin in plugins:
      logging.debug("Processing hunt %s with %s, batch %d", hunt_urn,
                    plugin_def.plugin_name, batch_index)

      try:
        plugin.ProcessResponses(batch)

        stats.STATS.IncrementCounter("hunt_results_ran_through_plugin",
                                     delta=len(batch),
                                     fields=[plugin_def.plugin_name])

        plugin_status = output_plugin.OutputPluginBatchProcessingStatus(
            plugin_descriptor=plugin_def,
            status="SUCCESS",
            batch_index=batch_index,
            batch_size=len(batch))
      except Exception as e:  # pylint: disable=broad-except
        stats.STATS.IncrementCounter("hunt_output_plugin_errors",
                                     fields=[plugin_def.plugin_name])

        plugin_status = output_plugin.OutputPluginBatchProcessingStatus(
            plugin_descriptor=plugin_def,
            status="ERROR",
            summary=utils.SmartStr(e),
            batch_index=batch_index,
            batch_size=len(batch))

        logging.exception("Error processing hunt results: hunt %s, "
                          "plugin %s, batch %d", hunt_urn,
                          plugin_def.plugin_name, batch_index)
        self.Log("Error processing hunt results (hunt %s, "
                 "plugin %s, batch %d): %s" %
                 (hunt_urn, plugin_def.plugin_name, batch_index, e))
        exceptions_by_plugin[plugin_def] = e

      # TODO(user): Change to use StaticAdd once all active hunts are
      # migrated.
      try:
        aff4.FACTORY.Open(self.StatusCollectionUrn(hunt_urn),
                          "PluginStatusCollection",
                          mode="w",
                          token=self.token).Add(plugin_status)
      except IOError:
        collects.PackedVersionedCollection.AddToCollection(
            self.StatusCollectionUrn(hunt_urn),
            [plugin_status], sync=False, token=self.token)

      if plugin_status.status == plugin_status.Status.ERROR:
        try:
          aff4.FACTORY.Open(self.ErrorsCollectionUrn(hunt_urn),
                            "PluginStatusCollection",
                            mode="w",
                            token=self.token).Add(plugin_status)
        except __HOLE__:
          collects.PackedVersionedCollection.AddToCollection(
              self.ErrorsCollectionUrn(hunt_urn),
              [plugin_status], sync=False, token=self.token)

    return exceptions_by_plugin
dataset/ETHPy150Open google/grr/grr/lib/hunts/standard.py/ProcessHuntResultsCronFlow.ApplyPluginsToBatch