Skip to content

Commit

Permalink
fix list
Browse files Browse the repository at this point in the history
  • Loading branch information
tilsche committed Aug 21, 2023
1 parent 71fe55b commit 2a5cb05
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions metricq_source_snmp/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))

Expand Down Expand Up @@ -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,
(
Expand Down

0 comments on commit 2a5cb05

Please sign in to comment.