| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # | |
| 3 # $Id: error.py 1142 2011-10-05 18:45:49Z g.rodola $ | |
| 4 # | |
| 5 # Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved. | |
| 6 # Use of this source code is governed by a BSD-style license that can be | |
| 7 # found in the LICENSE file. | |
| 8 | |
| 9 """psutil exception classes; do not import this directly""" | |
| 10 | |
| 11 | |
| 12 class Error(Exception): | |
| 13 """Base exception class. All other psutil exceptions inherit | |
| 14 from this one. | |
| 15 """ | |
| 16 | |
| 17 class NoSuchProcess(Error): | |
| 18 """Exception raised when a process with a certain PID doesn't | |
| 19 or no longer exists (zombie). | |
| 20 """ | |
| 21 | |
| 22 def __init__(self, pid, name=None, msg=None): | |
| 23 self.pid = pid | |
| 24 self.name = name | |
| 25 self.msg = msg | |
| 26 if msg is None: | |
| 27 if name: | |
| 28 details = "(pid=%s, name=%s)" % (self.pid, repr(self.name)) | |
| 29 else: | |
| 30 details = "(pid=%s)" % self.pid | |
| 31 self.msg = "process no longer exists " + details | |
| 32 | |
| 33 def __str__(self): | |
| 34 return self.msg | |
| 35 | |
| 36 | |
| 37 class AccessDenied(Error): | |
| 38 """Exception raised when permission to perform an action is denied.""" | |
| 39 | |
| 40 def __init__(self, pid=None, name=None, msg=None): | |
| 41 self.pid = pid | |
| 42 self.name = name | |
| 43 self.msg = msg | |
| 44 if msg is None: | |
| 45 if (pid is not None) and (name is not None): | |
| 46 self.msg = "(pid=%s, name=%s)" % (pid, repr(name)) | |
| 47 elif (pid is not None): | |
| 48 self.msg = "(pid=%s)" % self.pid | |
| 49 else: | |
| 50 self.msg = "" | |
| 51 | |
| 52 def __str__(self): | |
| 53 return self.msg | |
| 54 | |
| 55 | |
| 56 class TimeoutExpired(Error): | |
| 57 """Raised on Process.wait(timeout) if timeout expires and process | |
| 58 is still alive. | |
| 59 """ | |
| 60 | |
| 61 def __init__(self, pid=None, name=None): | |
| 62 self.pid = pid | |
| 63 self.name = name | |
| 64 if (pid is not None) and (name is not None): | |
| 65 self.msg = "(pid=%s, name=%s)" % (pid, repr(name)) | |
| 66 elif (pid is not None): | |
| 67 self.msg = "(pid=%s)" % self.pid | |
| 68 else: | |
| 69 self.msg = "" | |
| 70 | |
| 71 def __str__(self): | |
| 72 return self.msg | |
| 73 | |
| OLD | NEW |