MCPcopy Create free account
hub / github.com/ipython/ipython / num_cpus

Function num_cpus

IPython/utils/sysinfo.py:137–165  ·  view source on GitHub ↗

Return the effective number of CPUs in the system as an integer. This cross-platform function makes an attempt at finding the total number of available CPUs in the system, as returned by various underlying system and python calls. If it can't find a sensible answer, it returns 1 (thoug

()

Source from the content-addressed store, hash-verified

135
136
137def num_cpus():
138 """Return the effective number of CPUs in the system as an integer.
139
140 This cross-platform function makes an attempt at finding the total number of
141 available CPUs in the system, as returned by various underlying system and
142 python calls.
143
144 If it can't find a sensible answer, it returns 1 (though an error *may* make
145 it return a large positive number that's actually incorrect).
146 """
147
148 # Many thanks to the Parallel Python project (http://www.parallelpython.com)
149 # for the names of the keys we needed to look up for this function. This
150 # code was inspired by their equivalent function.
151
152 ncpufuncs = {'Linux':_num_cpus_unix,
153 'Darwin':_num_cpus_darwin,
154 'Windows':_num_cpus_windows
155 }
156
157 ncpufunc = ncpufuncs.get(platform.system(),
158 # default to unix version (Solaris, AIX, etc)
159 _num_cpus_unix)
160
161 try:
162 ncpus = max(1,int(ncpufunc()))
163 except:
164 ncpus = 1
165 return ncpus
166

Callers

nothing calls this directly

Calls 1

systemMethod · 0.80

Tested by

no test coverage detected