File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -48,12 +48,21 @@ def get_numa_cpus_conf() -> Dict[int, str]:
48
48
def get_number_of_sockets ():
49
49
if sys .platform == "win32" :
50
50
command = "wmic cpu get DeviceID"
51
- result = subprocess .check_output (command , shell = True , text = True )
51
+ result = subprocess .check_output (command , shell = False , text = True )
52
52
n_sockets = len (list (filter (lambda x : x .startswith ("CPU" ), result .split ("\n " ))))
53
53
elif sys .platform == "linux" :
54
- command = "lscpu | grep 'Socket(s):' | awk '{print $2}'"
55
- result = subprocess .check_output (command , shell = True , text = True )
56
- n_sockets = int (result .strip ("\n " ))
54
+ try :
55
+ _ , lscpu_text , _ = read_output_from_command ("lscpu" )
56
+ for line in lscpu_text .split ("\n " ):
57
+ if "Socket(s):" in line :
58
+ n_sockets = int (line .split (":" )[1 ].strip ())
59
+ break
60
+ else :
61
+ logger .warning ("Unable to find Socket(s) information in lscpu output" )
62
+ n_sockets = 1
63
+ except (FileNotFoundError , ValueError , IndexError ):
64
+ logger .warning ("Unable to get number of sockets via lscpu" )
65
+ n_sockets = 1
57
66
else :
58
67
logger .warning ("Unable to get number of sockets due to unknown sys.platform" )
59
68
n_sockets = 1
You can’t perform that action at this time.
0 commit comments