Commit 0b1be673 authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Log if number of workers is changed

parent 3a42af8e
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -3,11 +3,15 @@

# standard imports
from datetime import datetime
import logging
import multiprocessing
import resource
from typing import Union


logger = logging.getLogger(__name__)


def clamp_max_workers(max_workers: Union[int, None]) -> int:
    """Calculate the number of max workers.

@@ -15,7 +19,14 @@ def clamp_max_workers(max_workers: Union[int, None]) -> int:
    """
    if max_workers is None:
        max_workers = 0
    return min(resource.RLIMIT_NPROC, max(1, multiprocessing.cpu_count() - 2)) if max_workers <= 0 else max_workers

    result = min(resource.RLIMIT_NPROC, max(1, multiprocessing.cpu_count() - 2)) if max_workers <= 0 else max_workers

    # log if the value was different than what was asked for
    if max_workers == 0 and result != max_workers:
        logger.info(f"Due to system load, setting maximum workers to {result}")

    return result


def to_time_str(value: datetime = datetime.now()) -> str: