blob: b4e5d1ab767c6781d0b40be170ae8e3144fb0af5 [file] [log] [blame]
import os
import psutil
available_cpus = psutil.Process().cpu_affinity()
num_cpus = len(available_cpus)
max_vpp_cpus = os.getenv("MAX_VPP_CPUS", "auto").lower()
if max_vpp_cpus == "auto":
max_vpp_cpus = num_cpus
else:
try:
max_vpp_cpus = int(max_vpp_cpus)
except ValueError as e:
raise ValueError("Invalid MAX_VPP_CPUS value specified, valid "
"values are a positive integer or 'auto'") from e
if max_vpp_cpus <= 0:
raise ValueError("Invalid MAX_VPP_CPUS value specified, valid "
"values are a positive integer or 'auto'")
if max_vpp_cpus > num_cpus:
max_vpp_cpus = num_cpus