Refactored getting cores count to be work cross platform.

This commit is contained in:
CoopCoding 2021-06-25 12:35:09 +10:00
parent 3eb460dcf6
commit b4c198b0ef

View file

@ -19,6 +19,7 @@
from gi.repository import GObject
import os
import pkg_resources
import platform
class configuration(GObject.GObject):
@ -49,12 +50,11 @@ class configuration(GObject.GObject):
return config_folder
def _fill_config(self):
self.cores = 0
proc_file = open("/proc/cpuinfo", "r")
for line in proc_file:
if (line.startswith("processor")):
self.cores += 1
proc_file.close()
self.cores = os.cpu_count()
if 'sched_getaffinity' in dir(os):
self.cores = len(os.sched_getaffinity(0))
if platform.system() == 'FreeBSD':
self.cores = int(os.popen("sysctl -n kern.smp.cores").read().split('\n')[0])
is_local = None
self.log = ""