0 votes
1 view
in Python by (47.8k points)

I want to know the number of CPUs on the local machine using Python. The result should be user/real as output by time(1) when called with an optimally scaling userspace-only program.

1 Answer

0 votes
by (107k points)

For finding the number of CPUs which are using Python you can simply use:-

import multiprocessing

multiprocessing.cpu_count()

image

Another thing you can do is use the psutil library, which always turns out useful in these situations:-

import psutil

psutil.cpu_count()

image

This will work on any platform supported by psutil(Unix and Windows).

Related questions

0 votes
1 answer
0 votes
1 answer
asked Aug 30, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...