Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k 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 (106k 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
0 votes
1 answer
asked Aug 30, 2019 in Python by Sammy (47.6k points)
0 votes
4 answers

Browse Categories

...