From a1ae994cabff37eb86c6ca4564b4f193a73a7b0d Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Thu, 25 Nov 2021 11:33:35 +0100 Subject: fix #2023 [Linux] cpu_freq() return order is wrong on systems with > 9 CPUs. Signed-off-by: Giampaolo Rodola --- HISTORY.rst | 1 + psutil/_pslinux.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 139560f7..4b6ece58 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -54,6 +54,7 @@ XXXX-XX-XX (not thread-safe). - 1956_: [macOS] Process.cpu_times() reports incorrect timings on M1 machines. (patch by Olivier Dormond) +- 2023_: [Linux] cpu_freq() return order is wrong on systems with > 9 CPUs. 5.8.0 ===== diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 57925b87..1cbbec42 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -738,9 +738,10 @@ if os.path.exists("/sys/devices/system/cpu/cpufreq/policy0") or \ real-time. """ cpuinfo_freqs = _cpu_get_cpuinfo_freq() - paths = sorted( - glob.glob("/sys/devices/system/cpu/cpufreq/policy[0-9]*") or - glob.glob("/sys/devices/system/cpu/cpu[0-9]*/cpufreq")) + paths = \ + glob.glob("/sys/devices/system/cpu/cpufreq/policy[0-9]*") or \ + glob.glob("/sys/devices/system/cpu/cpu[0-9]*/cpufreq") + paths.sort(key=lambda x: int(re.search(r"[0-9]+", x).group())) ret = [] pjoin = os.path.join for i, path in enumerate(paths): -- cgit v1.2.1