49 self.todo = Condition(self.mutex) |
49 self.todo = Condition(self.mutex) |
50 self.done = Condition(self.mutex) |
50 self.done = Condition(self.mutex) |
51 self.free = Condition(self.mutex) |
51 self.free = Condition(self.mutex) |
52 self.job = None |
52 self.job = None |
53 |
53 |
|
54 def reraise(self, job): |
|
55 """ |
|
56 reraise exception happend in a job |
|
57 @param job: job where original exception happend |
|
58 """ |
|
59 exc_type = job.exc_info[0] |
|
60 exc_value = job.exc_info[1] |
|
61 exc_traceback = job.exc_info[2] |
|
62 six.reraise(exc_type, exc_value, exc_traceback) |
|
63 |
54 def runloop(self, *args, **kwargs): |
64 def runloop(self, *args, **kwargs): |
55 """ |
65 """ |
56 meant to be called by worker thread (blocking) |
66 meant to be called by worker thread (blocking) |
57 """ |
67 """ |
58 self._threadID = thread.get_ident() |
68 self._threadID = thread.get_ident() |
59 self.mutex.acquire() |
69 self.mutex.acquire() |
60 if args or kwargs: |
70 if args or kwargs: |
61 _job = job(*args, **kwargs) |
71 _job = job(*args, **kwargs) |
62 _job.do() |
72 _job.do() |
63 if _job.success: |
73 if not _job.success: |
64 # result is ignored |
74 self.reraise(_job) |
65 pass |
|
66 else: |
|
67 raise _job.exc_info[0], _job.exc_info[1], _job.exc_info[2] |
|
68 |
75 |
69 while not self._finish: |
76 while not self._finish: |
70 self.todo.wait() |
77 self.todo.wait() |
71 if self.job is not None: |
78 if self.job is not None: |
72 self.job.do() |
79 self.job.do() |