From f67e909b5942defb3e6ca99990cb30a782c9fd62 Mon Sep 17 00:00:00 2001 From: Martin Andersson Date: Wed, 10 Aug 2022 12:23:58 +0000 Subject: [PATCH] Catch exception in call to psutil .cmdline() (#413) There's a race condition where processes might disappear while filtering. The uncaught exception causes a crash. --- auto_cpufreq/core.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index 1a1adb5a..faf86c6e 100644 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -1175,8 +1175,12 @@ def is_running(program, argument): # iterate over all processes found by psutil # and find the one with name and args passed to the function for p in psutil.process_iter(): - for s in filter(lambda x: program in x, p.cmdline()): - if argument in p.cmdline(): + try: + cmd = p.cmdline(); + except: + continue + for s in filter(lambda x: program in x, cmd): + if argument in cmd: return True