| 66 | return x |
| 67 | |
| 68 | class DatabaseJob(): |
| 69 | def __init__(self, f, *args, **kwargs): |
| 70 | self.done = Event() |
| 71 | |
| 72 | self.f = f |
| 73 | self.args = args |
| 74 | self.kwargs = kwargs |
| 75 | |
| 76 | self.result = None |
| 77 | self.exception = False |
| 78 | |
| 79 | # import inspect |
| 80 | # self.frame = inspect.currentframe() |
| 81 | |
| 82 | def __repr__(self): |
| 83 | from os.path import basename |
| 84 | frame = self.frame.f_back |
| 85 | output = "" |
| 86 | for i in range(5): |
| 87 | output += "\t%s:%s, %s\n" % (basename(frame.f_code.co_filename), frame.f_lineno, frame.f_code.co_name) |
| 88 | frame = frame.f_back |
| 89 | del frame |
| 90 | del self.frame |
| 91 | |
| 92 | return "DataBase Job %s:%s\n%sResult: %s" % (self.f.__name__, self.args[1:], output, self.result) |
| 93 | |
| 94 | def processJob(self): |
| 95 | try: |
| 96 | self.result = self.f(*self.args, **self.kwargs) |
| 97 | except Exception, e: |
| 98 | print_exc() |
| 99 | try: |
| 100 | print "Database Error @", self.f.__name__, self.args[1:], self.kwargs, e |
| 101 | except: |
| 102 | pass |
| 103 | |
| 104 | self.exception = e |
| 105 | finally: |
| 106 | self.done.set() |
| 107 | |
| 108 | def wait(self): |
| 109 | self.done.wait() |
| 110 | |
| 111 | class DatabaseBackend(Thread): |
| 112 | subs = [] |
no outgoing calls
no test coverage detected