From 26789a2bb7c6fae8d756b4ca8236d1cfb5491be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 24 Nov 2017 11:26:27 +0100 Subject: [PATCH] CPU frequency might be reported as None Don't die when that's the case. --- src/octoprint/environment.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/octoprint/environment.py b/src/octoprint/environment.py index 2da7bcc4..13c513ff 100644 --- a/src/octoprint/environment.py +++ b/src/octoprint/environment.py @@ -75,9 +75,18 @@ class EnvironmentDetector(object): return result def _detect_hardware(self): - return dict(cores=psutil.cpu_count(), - freq=psutil.cpu_freq().max, - ram=get_formatted_size(psutil.virtual_memory().total)) + cores = psutil.cpu_count() + cpu_freq = psutil.cpu_freq() + ram = psutil.virtual_memory() + + result = dict() + if cores: + result["cores"] = cores + if cpu_freq and hasattr(cpu_freq, "max"): + result["freq"] = cpu_freq.max + if ram and hasattr(ram, "total"): + result["ram"] = ram.total + return result def _detect_from_plugins(self): result = dict()