kiranvizru / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

Debian: Vmstat access error with non root user #346

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

>>> import psutil
>>> psutil.__version__
'0.6.1'
>>> psutil.swap_memory()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/psutil/__init__.py", line 1000, in swap_memory
    return _psplatform.swap_memory()
  File "/usr/local/lib/python2.6/dist-packages/psutil/_pslinux.py", line 153, in swap_memory
    f = open("/proc/vmstat", "r")
IOError: [Errno 13] Permission denied: '/proc/vmstat'
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit

On what operating system? Is it 32bit or 64bit version?
64 bits

Original issue reported on code.google.com by nicolash...@gmail.com on 26 Dec 2012 at 9:12

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Uh! Interesting. 
Why do you consider this to be a bug with psutil though?
The only debatable argument is whether to turn that into an AccessDenied 
exception in order to be consistent with psutil.Process class, but other than 
that psutil can't and shouldn't do anything about it.

Original comment by g.rodola on 28 Dec 2012 at 3:42

GoogleCodeExporter commented 9 years ago
Agree with you. PsUtil should generate an error but an internal error like 
psutil.AccessDenied will be better.

Regards

Original comment by nicolash...@gmail.com on 18 Jan 2013 at 4:26

GoogleCodeExporter commented 9 years ago
I'm -1 about wrapping all non-process related functions in order to generate 
AccessDenied exceptions though. 
The chances we get EPERM are very rare, the original OSError exception is 
clearer and AccessDenied class is incompatible as it expects a pid and a name 
argument [1], both of which refer to a process.  

[1] http://code.google.com/p/psutil/source/browse/trunk/psutil/error.py#37

Original comment by g.rodola on 20 Jan 2013 at 6:58