summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Schlömer <nico.schloemer@gmail.com>2022-03-08 09:41:17 +0100
committerGitHub <noreply@github.com>2022-03-08 09:41:17 +0100
commit27e963b2a9cdf2059aab65d4adbce046d5c9e05d (patch)
tree03828eaaad4d39dd1f107f28071b6963aaf3b851
parent29e0fe5311a1fd199422c0480d0a7ebae89d1354 (diff)
parente929e222d3c03cab8bffa06fcf73186a2997ac97 (diff)
Merge pull request #76 from nschloe/fix-m1-freqv0.2.3
Fix M1 cpu_freq
-rw-r--r--src/tiptop/__about__.py2
-rw-r--r--src/tiptop/_cpu.py22
2 files changed, 12 insertions, 12 deletions
diff --git a/src/tiptop/__about__.py b/src/tiptop/__about__.py
index b5fdc75..d31c31e 100644
--- a/src/tiptop/__about__.py
+++ b/src/tiptop/__about__.py
@@ -1 +1 @@
-__version__ = "0.2.2"
+__version__ = "0.2.3"
diff --git a/src/tiptop/_cpu.py b/src/tiptop/_cpu.py
index e217f95..26d5085 100644
--- a/src/tiptop/_cpu.py
+++ b/src/tiptop/_cpu.py
@@ -98,21 +98,21 @@ def get_current_freq():
"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq",
]
for candidate in candidates:
- file = Path(candidate)
- if file.exists():
- with open(file) as f:
+ if Path(candidate).exists():
+ with open(candidate) as f:
content = f.read()
return int(content) / 1000
- c = psutil.cpu_freq()
- if hasattr(c, "current"):
- cpu_freq = c.current
- if psutil.__version__ == "5.9.0" and cpu_freq < 10:
- # Work around <https://github.com/giampaolo/psutil/issues/2049>
- cpu_freq *= 1000
- return cpu_freq
+ try:
+ cpu_freq = psutil.cpu_freq().current
+ except Exception:
+ # https://github.com/nschloe/tiptop/issues/25#issuecomment-1061390966
+ return None
- return None
+ if psutil.__version__ == "5.9.0" and cpu_freq < 10:
+ # Work around <https://github.com/giampaolo/psutil/issues/2049>
+ cpu_freq *= 1000
+ return cpu_freq
class CPU(Widget):