Python os.sysconf_names() Examples
The following are 4
code examples of os.sysconf_names().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: Options.py From 802.11ah-ns3 with GNU General Public License v2.0 | 7 votes |
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
Example #2
Source File: scheduling.py From me-ica with GNU Lesser General Public License v2.1 | 6 votes |
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
Example #3
Source File: util.py From alive with Apache License 2.0 | 6 votes |
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
Example #4
Source File: Options.py From royal-chaos with MIT License | 6 votes |
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