python psutil get numbers of cpu sockets

2.6k views Asked by At

it's possible to know numbers of sockets in my computer with python (and psutil ?)

for example with psutil i can to get numbers of core, but can i the number of sockets in mothercard ?

My computer have 2 sockets (and 2 xeon cpu)

2

There are 2 answers

6
Maurice Meyer On

psutils provides cpu_count function with parameters logical=True/False. logical=False returns the number of physical cores only.

psutil.cpu_count(logical=False)
0
Maximilian Peters On

psutil does not return this kind of information (as far as I could tell from the documentation and the source code).

If you are on Linux you can get the information in python with the following code:

import subprocess
cpu_sockets =  int(subprocess.check_output('cat /proc/cpuinfo | grep "physical id" | sort -u | wc -l', shell=True))

Returns 1 on a single socket system (my Amazon server) and 2 on my Xeon workstation.