Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
1 #!/usr/bin/env python
3 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 """psutil exception classes.
8 Not supposed to be used / imported directly.
9 Instead use psutil.NoSuchProcess, etc.
10 """
13 class Error(Exception):
14 """Base exception class. All other psutil exceptions inherit
15 from this one.
16 """
18 class NoSuchProcess(Error):
19 """Exception raised when a process with a certain PID doesn't
20 or no longer exists (zombie).
21 """
23 def __init__(self, pid, name=None, msg=None):
24 self.pid = pid
25 self.name = name
26 self.msg = msg
27 if msg is None:
28 if name:
29 details = "(pid=%s, name=%s)" % (self.pid, repr(self.name))
30 else:
31 details = "(pid=%s)" % self.pid
32 self.msg = "process no longer exists " + details
34 def __str__(self):
35 return self.msg
38 class AccessDenied(Error):
39 """Exception raised when permission to perform an action is denied."""
41 def __init__(self, pid=None, name=None, msg=None):
42 self.pid = pid
43 self.name = name
44 self.msg = msg
45 if msg is None:
46 if (pid is not None) and (name is not None):
47 self.msg = "(pid=%s, name=%s)" % (pid, repr(name))
48 elif (pid is not None):
49 self.msg = "(pid=%s)" % self.pid
50 else:
51 self.msg = ""
53 def __str__(self):
54 return self.msg
57 class TimeoutExpired(Error):
58 """Raised on Process.wait(timeout) if timeout expires and process
59 is still alive.
60 """
62 def __init__(self, pid=None, name=None):
63 self.pid = pid
64 self.name = name
65 if (pid is not None) and (name is not None):
66 self.msg = "(pid=%s, name=%s)" % (pid, repr(name))
67 elif (pid is not None):
68 self.msg = "(pid=%s)" % self.pid
69 else:
70 self.msg = ""
72 def __str__(self):
73 return self.msg