'Assign a bunch of metrics for a process to analyze.'

def spin_process(self, i, unique_metrics):

    keys_per_processor = int(ceil((float(len(unique_metrics)) / float(settings.ANALYZER_PROCESSES))))
    if (i == settings.ANALYZER_PROCESSES):
        assigned_max = len(unique_metrics)
    else:
        assigned_max = (i * keys_per_processor)
    assigned_min = (assigned_max - keys_per_processor)
    assigned_keys = range(assigned_min, assigned_max)
    assigned_metrics = [unique_metrics[index] for index in assigned_keys]
    if (len(assigned_metrics) == 0):
        return
    raw_assigned = self.redis_conn.mget(assigned_metrics)
    exceptions = defaultdict(int)
    anomaly_breakdown = defaultdict(int)
    for (i, metric_name) in enumerate(assigned_metrics):
        self.check_if_parent_is_alive()
        try:
            raw_series = raw_assigned[i]
            unpacker = Unpacker(use_list=False)
            unpacker.feed(raw_series)
            timeseries = list(unpacker)
            (anomalous, ensemble, datapoint) = run_selected_algorithm(timeseries, metric_name)
            if anomalous:
                base_name = metric_name.replace(settings.FULL_NAMESPACE, '', 1)
                metric = [datapoint, base_name]
                self.anomalous_metrics.append(metric)
                for (index, value) in enumerate(ensemble):
                    if value:
                        algorithm = settings.ALGORITHMS[index]
                        anomaly_breakdown[algorithm] += 1
        except TypeError:
            exceptions['DeletedByRoomba'] += 1
        except TooShort:
            exceptions['TooShort'] += 1
        except Stale:
            exceptions['Stale'] += 1
        except Boring:
            exceptions['Boring'] += 1
        except:
            exceptions['Other'] += 1
            logger.info(traceback.format_exc())
    for (key, value) in anomaly_breakdown.items():
        self.anomaly_breakdown_q.put((key, value))
    for (key, value) in exceptions.items():
        self.exceptions_q.put((key, value))
