@@ -118,49 +118,25 @@ def sys_info():
118118 """
119119 return pprint .pformat (get_sys_info ())
120120
121- def _num_cpus_unix ():
122- """Return the number of active CPUs on a Unix system."""
123- return os .sysconf ("SC_NPROCESSORS_ONLN" )
124-
125-
126- def _num_cpus_darwin ():
127- """Return the number of active CPUs on a Darwin system."""
128- p = subprocess .Popen (['sysctl' ,'-n' ,'hw.ncpu' ],stdout = subprocess .PIPE )
129- return p .stdout .read ()
130-
131-
132- def _num_cpus_windows ():
133- """Return the number of active CPUs on a Windows system."""
134- return os .environ .get ("NUMBER_OF_PROCESSORS" )
135-
136121
137122def 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.
123+ """DEPRECATED
143124
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- """
125+ Return the effective number of CPUs in the system as an integer.
147126
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 .
127+ This cross-platform function makes an attempt at finding the total number of
128+ available CPUs in the system, as returned by various underlying system and
129+ python calls .
151130
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 )
131+ If it can't find a sensible answer, it returns 1 (though an error *may* make
132+ it return a large positive number that's actually incorrect).
133+ """
134+ import warnings
160135
161- try :
162- ncpus = max ( 1 , int ( ncpufunc ()))
163- except :
164- ncpus = 1
165- return ncpus
136+ warnings . warn (
137+ "`num_cpus` is deprecated since IPython 8.0. Use `os.cpu_count` instead." ,
138+ DeprecationWarning ,
139+ stacklevel = 2 ,
140+ )
166141
142+ return os .cpu_count () or 1
0 commit comments