Skip to content

Commit 9886219

Browse files
committed
Make the statistics collection safer/possible on macOS.
The stats.py module pulls in a package which might not be installed, and isn't present on my macOS system - the pyamdgpuinfo package. This change makes the import silent, and allows it to be auto-detected as absent, rather than failing to run. Similarly, the psutil package doesn't appear to provide the sensors_temperature interface, so this has been made safe if it is not present.
1 parent dee8833 commit 9886219

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

library/stats.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import GPUtil
44
import psutil
5-
6-
if os.name == 'posix':
5+
try:
76
import pyamdgpuinfo
7+
except ImportError:
8+
pyamdgpuinfo = None
89

910
import library.config as config
1011
from library.display import display
@@ -133,11 +134,14 @@ def load():
133134

134135
@staticmethod
135136
def is_temperature_available():
136-
if os.name == 'posix':
137+
try:
137138
if 'coretemp' in psutil.sensors_temperatures() or 'k10temp' in psutil.sensors_temperatures():
138139
return True
139-
140-
return False
140+
else:
141+
return False
142+
except AttributeError:
143+
# sensors_temperatures may not be available at all
144+
return False
141145

142146
@staticmethod
143147
def temperature():
@@ -299,7 +303,9 @@ def stats():
299303

300304
@staticmethod
301305
def is_available():
302-
return os.name == 'posix' and pyamdgpuinfo.detect_gpus() > 0
306+
if not pyamdgpuinfo:
307+
return False
308+
return pyamdgpuinfo.detect_gpus() > 0
303309

304310

305311
class Memory:

0 commit comments

Comments
 (0)