Catch exception in call to psutil .cmdline() #413
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There's a race condition where processes might disappear while filtering. The uncaught exception causes a crash.
See the following stack trace:
Traceback (most recent call last):
File "/usr/bin/auto-cpufreq", line 226, in
main()
File "/usr/lib/python3.10/site-packages/click/core.py", line 1130, in call
return self.main(*args, **kwargs)
File "/usr/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/usr/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/usr/bin/auto-cpufreq", line 117, in main
running_daemon()
File "/usr/lib/python3.10/site-packages/auto_cpufreq/core.py", line 1190, in running_daemon
if is_running("auto-cpufreq", "--daemon"):
File "/usr/lib/python3.10/site-packages/auto_cpufreq/core.py", line 1175, in is_running
for s in filter(lambda x: program in x, p.cmdline()):
File "/usr/lib/python3.10/site-packages/psutil/init.py", line 684, in cmdline
return self._proc.cmdline()
File "/usr/lib/python3.10/site-packages/psutil/_pslinux.py", line 1668, in wrapper
raise NoSuchProcess(self.pid, self._name)
psutil.NoSuchProcess: process no longer exists (pid=669342)