-
-
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
[Linux] Process.open_files()
crashes if an open file is not accessible
#2124
Comments
The code checks whether the path is a regular file: Lines 2205 to 2209 in c13017f
The check is needed because /proc/<PID>/fd can return all sorts of file descriptor types (pipes , unix sockets, directories, ...), but open_files() is designed to return regular files only, so unfortunately there is no way to avoid EPERM.
After you run your script also
...meaning this is a standard UNIX permission issue and shouldn't be considered a psutil bug. |
Of course |
Yes. The same way it's not accessible to
As a general rule, psutil tends to avoid returning incomplete results and prefers to "crash" with With that said, it is true that sometimes it is desirable to get incomplete results, as it seems this is the case. Perhaps def open_files(ignore_eperm=False) ...and perhaps |
Thanks a lot for the detailed reasoning. Knowing that the current behavior is actually expected, I'll try to get those users who stumbled across this behavior involved. An API extension such as an Thanks for reopening. I'll try to get people directly affected by this issue involved in this discussion. |
Proposal: #2329. |
Summary
Description
Process.open_files()
crashes if an open file is not accessibleTake the following reproducer:
Expected result: Gracefully handle inaccessible files, as callers of
open_files
do not expect any exceptions.Actual result: An exception is thrown. While handling the exception, another exception is thrown.
Output of the reproducer:
The condition under which this error occurs may seem quite odd. Why should a process have an open file descriptor to a file that it cannot see? Turns out that this is a practical issue when your python process is launched from a process that entered a Linux namespace via setns(2), the bind mount referencing that namespace is only accessible to root and privileges are dropped before launching python. This happens in systems that manage and isolate user processes from each other, such as the SLURM workload manager used in many HPC clusters.
The text was updated successfully, but these errors were encountered: