executorlib.standalone.inputcheck.validate_number_of_cores

executorlib.standalone.inputcheck.validate_number_of_cores#

executorlib.standalone.inputcheck.validate_number_of_cores(max_cores: int | None = None, max_workers: int | None = None, cores_per_worker: int | None = 1, set_local_cores: bool = False) int[source]#

Validate the number of cores and return the number of workers to use.

Precedence: max_cores / cores_per_worker > max_workers > CPU count (with warning).

Parameters:
  • max_cores (int, optional) – Total number of cores available.

  • max_workers (int, optional) – Explicit number of parallel workers.

  • cores_per_worker (int, optional) – Number of cores allocated to each worker. Defaults to 1.

  • set_local_cores (bool) – When True, fall back to the local CPU count if neither max_cores nor max_workers is given instead of raising an error. Defaults to False.

Returns:

Number of parallel workers to use.

Return type:

int

Raises:

ValueError – If neither max_cores nor max_workers is set and set_local_cores is False.