From e2ebbccb2e40f17310fa91ab0925866d8241a26a Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Mon, 14 Dec 2020 10:58:46 +0200 Subject: [PATCH] [scripts/welcome] fix crash on newer Android versions where /proc/stat is inaccessible --- script-resources/welcome/system_info.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/script-resources/welcome/system_info.py b/script-resources/welcome/system_info.py index e858f7c..d840055 100644 --- a/script-resources/welcome/system_info.py +++ b/script-resources/welcome/system_info.py @@ -48,7 +48,9 @@ def get_system_info(): info_lines.append("") - info("CPU Usage", "%s", _get_cpu_usage()) + cpu_usage_info = _get_cpu_usage() + if cpu_usage_info is not None: + info("CPU Usage", "%s", cpu_usage_info) info("Memory", "%s / %s (%s)", *_get_memory()) for disk_info in _get_disks(): @@ -109,7 +111,11 @@ def _get_shell(): def _get_cpu_usage(): - percent = psutil.cpu_percent() + try: + percent = psutil.cpu_percent() + except Exception as e: + print("Error in _get_cpu_usage:", e) + return None return colorize_percent(percent, warning=60, critical=80) @@ -153,7 +159,7 @@ def _get_battery(): try: battery = psutil.sensors_battery() except Exception as e: - print(e) + print("Error in _get_battery:", e) return None if battery is None: