本文整理汇总了Python中os.sysconf_names方法的典型用法代码示例。如果您正苦于以下问题:Python os.sysconf_names方法的具体用法?Python os.sysconf_names怎么用?Python os.sysconf_names使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.sysconf_names方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cpu_count
# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf_names [as 别名]
def cpu_count():
"""Return the number of CPU cores."""
try:
return multiprocessing.cpu_count()
# TODO: remove except clause once we support only python >= 2.6
except NameError:
## This code part is taken from parallel python.
# Linux, Unix and MacOS
if hasattr(os, "sysconf"):
if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
# Linux & Unix
n_cpus = os.sysconf("SC_NPROCESSORS_ONLN")
if isinstance(n_cpus, int) and n_cpus > 0:
return n_cpus
else:
# OSX
return int(os.popen2("sysctl -n hw.ncpu")[1].read())
# Windows
if "NUMBER_OF_PROCESSORS" in os.environ:
n_cpus = int(os.environ["NUMBER_OF_PROCESSORS"])
if n_cpus > 0:
return n_cpus
# Default
return 1
示例2: detectCPUs
# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf_names [as 别名]
def detectCPUs():
"""
Detects the number of CPUs on a system. Cribbed from pp.
"""
# Linux, Unix and MacOS:
if hasattr(os, "sysconf"):
if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
# Linux & Unix:
ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
if isinstance(ncpus, int) and ncpus > 0:
return ncpus
else: # OSX:
return int(capture(['sysctl', '-n', 'hw.ncpu']))
# Windows:
if "NUMBER_OF_PROCESSORS" in os.environ:
ncpus = int(os.environ["NUMBER_OF_PROCESSORS"])
if ncpus > 0:
return ncpus
return 1 # Default
示例3: jobs
# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf_names [as 别名]
def jobs(self):
count=int(os.environ.get('JOBS',0))
if count<1:
if'NUMBER_OF_PROCESSORS'in os.environ:
count=int(os.environ.get('NUMBER_OF_PROCESSORS',1))
else:
if hasattr(os,'sysconf_names'):
if'SC_NPROCESSORS_ONLN'in os.sysconf_names:
count=int(os.sysconf('SC_NPROCESSORS_ONLN'))
elif'SC_NPROCESSORS_CONF'in os.sysconf_names:
count=int(os.sysconf('SC_NPROCESSORS_CONF'))
if not count and os.name not in('nt','java'):
try:
tmp=self.cmd_and_log(['sysctl','-n','hw.ncpu'],quiet=0)
except Exception:
pass
else:
if re.match('^[0-9]+$',tmp):
count=int(tmp)
if count<1:
count=1
elif count>1024:
count=1024
return count