File indexing completed on 2025-02-16 05:12:09
0001 import math 0002 import multiprocessing 0003 0004 from conans.util.files import load 0005 0006 0007 def build_jobs(conanfile): 0008 njobs = conanfile.conf.get("tools.build:jobs", 0009 default=_cpu_count(), 0010 check_type=int) 0011 return njobs 0012 0013 0014 def _cpu_count(): 0015 try: 0016 try: 0017 # This is necessary to deduce docker cpu_count 0018 cfs_quota_us = int(load("/sys/fs/cgroup/cpu/cpu.cfs_quota_us")) 0019 cfs_period_us = int(load("/sys/fs/cgroup/cpu/cpu.cfs_period_us")) 0020 if cfs_quota_us > 0 and cfs_period_us > 0: 0021 return int(math.ceil(cfs_quota_us / cfs_period_us)) 0022 except (EnvironmentError, TypeError): 0023 pass 0024 return multiprocessing.cpu_count() 0025 except NotImplementedError: 0026 # print("multiprocessing.cpu_count() not implemented. Defaulting to 1 cpu") 0027 return 1 # Safe guess