You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
psutil provides different APIs that return multiple results (a list or a dict of elements), like psutil.Process.open_files() or psutil.net_connections(). It can happen that these API raise AccessDenied because of insufficient permissions, despite the fact that internally some information is collected (and discarded). Over the years there has been some demand to ignore AccessDenied and return a partial result instead:
In the past I explained why letting AccessDenied propagate is a good thing (see #2124 (comment)). Nevertheless, the use case to be able to retrieve a partial result instead of AccessDenied appears justified.
Proposal
The proposal is to identify for which APIs it make sense to do this, and either:
introduce an ignore_eperm (or similar) parameter to the function signatures that require it, e.g.
The first approach seems shorter and cleaner, but it requires changing the signature of multiple APIs (and the doc must reflect that).
The second approach appears more generic, but it's probably harder to understand for non-experts. Also, I guess it's too generic, because only certain APIs will set partial_result, so one may erroneously use the try/except idiom above and expect some result for an API which does not implement this contract.
It must be noted that also gopsutil project is puzzled by these sort of API design questions:
Problem
psutil provides different APIs that return multiple results (a list or a dict of elements), like
psutil.Process.open_files()
orpsutil.net_connections()
. It can happen that these API raiseAccessDenied
because of insufficient permissions, despite the fact that internally some information is collected (and discarded). Over the years there has been some demand to ignoreAccessDenied
and return a partial result instead:disk_io_counters
#1974 (disk_io_counters
on Windows)open_files()
function crashes on inaccessible files. #2203 (open_files
on Windows)open_files()
function crashes on inaccessible files. #2203 (open_files
on Windows)Process.open_files()
crashes if an open file is not accessible #2124 (open_files
on Linux)In the past I explained why letting
AccessDenied
propagate is a good thing (see #2124 (comment)). Nevertheless, the use case to be able to retrieve a partial result instead ofAccessDenied
appears justified.Proposal
The proposal is to identify for which APIs it make sense to do this, and either:
ignore_eperm
(or similar) parameter to the function signatures that require it, e.g.partial_result
attribute to theAccessDenied
instance, so that one can do:The first approach seems shorter and cleaner, but it requires changing the signature of multiple APIs (and the doc must reflect that).
The second approach appears more generic, but it's probably harder to understand for non-experts. Also, I guess it's too generic, because only certain APIs will set
partial_result
, so one may erroneously use thetry/except
idiom above and expect some result for an API which does not implement this contract.It must be noted that also gopsutil project is puzzled by these sort of API design questions:
APIs
Potential API candidates are:
Process:
psutil.Process.children()
psutil.Process.connections()
psutil.Process.open_files()
psutil.Process.parents()
psutil.Process.threads()
System:
psutil.disk_io_counters()
psutil.disk_partitions()
psutil.net_connections()
psutil.net_io_counters()
psutil.users()
The text was updated successfully, but these errors were encountered: