-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
About Error FileNotFoundError: [Errno 2] No such file or directory: '/proc/12825/stat'
the some suggest
#2418
Comments
I cannot understand much from your report. Please paste your code and the full traceback message. |
Are you saying file |
yes ,I met the problem just not exist |
Can you do |
I tried |
So the |
not empty, there are some files, but no |
OK, paste those files. Paste the output of |
Same Error here, a random error that happens not very often at all (I would say once every 1k calls, we use this to list the most expensive processes in RAM periodically, and rarely, in out CI, it fails:
=> Looks like a race concurrency issue. When this happens, while the call: |
@pierresouchay mmm this indeed appears to be a race condition. My interpretation is the following:
My interpretation is that, when a process is terminated, |
Yes, I have the same interpretation (and it makes sense, likely the kernel might not remove all the underlying files and /proc/PID in an atomic call (most likely iteratively cleaned up during the various phases of process cleanup |
Mmm this is a hard one to fix. It's not obvious how we can distinguish between a /proc file that legitimately does not exist from "process is gone". |
It would be very useful to know what files An easy way to solve this would be the following: --- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -1722,7 +1722,9 @@ def wrap_exceptions(fun):
raise NoSuchProcess(self.pid, self._name)
except FileNotFoundError:
self._raise_if_zombie()
- if not os.path.exists("%s/%s" % (self._procfs_path, self.pid)):
+ if not os.path.exists("%s/%s/stat" % (self._procfs_path, self.pid)):
raise NoSuchProcess(self.pid, self._name)
raise We assume that if |
I have no clue... but it is hard to get, since it is a race condition. In my understanding, your patch looks like a safe bet: /proc/PID/stat not existing -> likely no such process even if /proc/PID is found (I think that's the case for zombie processes for instance) |
Thank you @giampaolo : you rock! |
when I was useing the function
process_iter
discover a not myself can catch the error。For errors like
FileNotFoundError: [Errno 2] No such file or directory: '/proc/xxx/stat'
。I searched for problems in lssues , but found that the latest version didn't fix them. Through the source code found that this function only catch the NoSuchProcess exception,and this error I think is a problem with
pids
functino,pids
from /proc dir fetch a unusua path,lead to open the path/proc/xxx/stat
raised an exception,so we can do try/catch the FileNotFoundError error at the open file location。The text was updated successfully, but these errors were encountered: