mirror of
https://github.com/esphome/esphome.git
synced 2025-09-23 05:32:22 +01:00
Use the process CPU count to determine how many children to create (#8268)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
@@ -94,10 +93,19 @@ def valid_project_name(value: str):
|
||||
return value
|
||||
|
||||
|
||||
def get_usable_cpu_count() -> int:
|
||||
"""Return the number of CPUs that can be used for processes.
|
||||
On Python 3.13+ this is the number of CPUs that can be used for processes.
|
||||
On older Python versions this is the number of CPUs.
|
||||
"""
|
||||
return (
|
||||
os.process_cpu_count() if hasattr(os, "process_cpu_count") else os.cpu_count()
|
||||
)
|
||||
|
||||
|
||||
if "ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT" in os.environ:
|
||||
_compile_process_limit_default = min(
|
||||
int(os.environ["ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT"]),
|
||||
multiprocessing.cpu_count(),
|
||||
int(os.environ["ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT"]), get_usable_cpu_count()
|
||||
)
|
||||
else:
|
||||
_compile_process_limit_default = cv.UNDEFINED
|
||||
@@ -156,7 +164,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
),
|
||||
cv.Optional(
|
||||
CONF_COMPILE_PROCESS_LIMIT, default=_compile_process_limit_default
|
||||
): cv.int_range(min=1, max=multiprocessing.cpu_count()),
|
||||
): cv.int_range(min=1, max=get_usable_cpu_count()),
|
||||
}
|
||||
),
|
||||
validate_hostname,
|
||||
|
Reference in New Issue
Block a user