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.
This commit is contained in:
Martin Andersson 2022-08-10 12:23:58 +00:00 committed by GitHub
parent 7b81b4aa30
commit f67e909b59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -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