summaryrefslogtreecommitdiff
path: root/psutil/_psbsd.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-06-28 15:12:56 +0200
committerGitHub <noreply@github.com>2019-06-28 15:12:56 +0200
commitc10df5aa04e1ced58d19501fa42f08c1b909b83d (patch)
tree053e13469d3959524d0cdb556aafe55ba753256c /psutil/_psbsd.py
parentadc28e4bd6534641f2c85ccc42529e6f25e97867 (diff)
downloadpsutil-c10df5aa04e1ced58d19501fa42f08c1b909b83d.tar.gz
PEP-3151: backport FS exceptions to Python 2 (#1544)
Diffstat (limited to 'psutil/_psbsd.py')
-rw-r--r--psutil/_psbsd.py36
1 files changed, 19 insertions, 17 deletions
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index eccc96a1..2f41dc0b 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -24,8 +24,12 @@ from ._common import memoize_when_activated
from ._common import NETBSD
from ._common import OPENBSD
from ._common import usage_percent
+from ._compat import FileNotFoundError
+from ._compat import PermissionError
+from ._compat import ProcessLookupError
from ._compat import which
+
__extra__all__ = []
@@ -550,19 +554,19 @@ def wrap_exceptions(fun):
def wrapper(self, *args, **kwargs):
try:
return fun(self, *args, **kwargs)
- except OSError as err:
+ except ProcessLookupError:
+ if not pid_exists(self.pid):
+ raise NoSuchProcess(self.pid, self._name)
+ else:
+ raise ZombieProcess(self.pid, self._name, self._ppid)
+ except PermissionError:
+ raise AccessDenied(self.pid, self._name)
+ except OSError:
if self.pid == 0:
if 0 in pids():
raise AccessDenied(self.pid, self._name)
else:
raise
- if err.errno == errno.ESRCH:
- if not pid_exists(self.pid):
- raise NoSuchProcess(self.pid, self._name)
- else:
- raise ZombieProcess(self.pid, self._name, self._ppid)
- if err.errno in (errno.EPERM, errno.EACCES):
- raise AccessDenied(self.pid, self._name)
raise
return wrapper
@@ -572,18 +576,16 @@ def wrap_exceptions_procfs(inst):
"""Same as above, for routines relying on reading /proc fs."""
try:
yield
- except EnvironmentError as err:
+ except (ProcessLookupError, FileNotFoundError):
# ENOENT (no such file or directory) gets raised on open().
# ESRCH (no such process) can get raised on read() if
# process is gone in meantime.
- if err.errno in (errno.ENOENT, errno.ESRCH):
- if not pid_exists(inst.pid):
- raise NoSuchProcess(inst.pid, inst._name)
- else:
- raise ZombieProcess(inst.pid, inst._name, inst._ppid)
- if err.errno in (errno.EPERM, errno.EACCES):
- raise AccessDenied(inst.pid, inst._name)
- raise
+ if not pid_exists(inst.pid):
+ raise NoSuchProcess(inst.pid, inst._name)
+ else:
+ raise ZombieProcess(inst.pid, inst._name, inst._ppid)
+ except PermissionError:
+ raise AccessDenied(inst.pid, inst._name)
class Process(object):