本文整理匯總了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