3

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 Answers2

2

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.

Courtney7
  • 348
  • 4
  • 11
Maximilian Peters
  • 30,348
  • 12
  • 86
  • 99
-1

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

psutil.cpu_count(logical=False)
Maurice Meyer
  • 17,279
  • 4
  • 30
  • 47
  • 1
    this is not my question, i ask numbers of sockets in the motherboard, not numbers of physical cpu – user7379681 Jan 09 '17 at 15:32
  • I dont think the socket count is provided by psutils. On linux you could parse the output of [lscpu](https://linux.die.net/man/1/lscpu) – Maurice Meyer Jan 09 '17 at 15:38
  • 1
    I'm psutil author and I'm curious: what's your use case? I always refrained from exposing this information because I couldn't see a use case. – Giampaolo Rodolà Jan 10 '17 at 01:05
  • ok, thnak's for your answer, i need number socket because i create program to check system configuration (in a server) – user7379681 Jan 10 '17 at 08:08
  • @Giampaolo Rodolà knowing number of sockets could potentially allow more efficient planning on NUMA vs not-Numa systems. Also licensing of many products such as Windows server, MS Sql Server, Oracle, Vmware and many more are dependent on number of sockets. Hope this gives enough reasons? ) So maybe, if not hard to add, you can include this feature in some upcoming release... – Anatoly Alekseev Aug 14 '19 at 14:04