From 2a5cb050268af965f694e287097453b0828ade15 Mon Sep 17 00:00:00 2001 From: Thomas Ilsche Date: Mon, 21 Aug 2023 18:46:08 +0200 Subject: [PATCH] fix list --- metricq_source_snmp/main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/metricq_source_snmp/main.py b/metricq_source_snmp/main.py index 466f8e0..9a5c35e 100644 --- a/metricq_source_snmp/main.py +++ b/metricq_source_snmp/main.py @@ -10,9 +10,9 @@ import traceback from collections import defaultdict from collections.abc import Awaitable -from itertools import islice + from queue import Empty -from typing import Any, Mapping, Optional, Sequence +from typing import Any, Mapping, Optional, Sequence, TypeVar, Iterable import click import click_log # type: ignore @@ -31,8 +31,11 @@ from .version import __version__ # noqa: F401 # magic import for automatic version +T = TypeVar("T") + + # https://stackoverflow.com/a/2135920 -def split(a, n): +def split(a: list[T], n: int) -> Iterable[list[T]]: k, m = divmod(len(a), n) return (a[i * k + min(i, m) : (i + 1) * k + min(i + 1, m)] for i in range(n)) @@ -303,7 +306,7 @@ async def _on_config( ) # distribute host configurations to workers - for chunk in split(objects_by_host.keys(), num_procs): + for chunk in split(list(objects_by_host.keys()), num_procs): self.workers.apply_async( mp_worker, (