def get_logical_cpu_count():
if psutil is not None:
# Number of logical CPUs
cpu_count = psutil.cpu_count()
elif hasattr(os, 'cpu_count'):
# Python 3.4
cpu_count = os.cpu_count()
else:
cpu_count = None
try:
import multiprocessing
except ImportError:
pass
else:
try:
cpu_count = multiprocessing.cpu_count()
except NotImplementedError:
pass
if cpu_count is not None and cpu_count < 1:
return None
return cpu_count
评论列表
文章目录