Revision 2f4e1516 lib/workerpool.py
b/lib/workerpool.py | ||
---|---|---|
52 | 52 |
self._current_task = None |
53 | 53 |
|
54 | 54 |
def ShouldTerminate(self): |
55 |
"""Returns whether a worker should terminate. |
|
55 |
"""Returns whether this worker should terminate. |
|
56 |
|
|
57 |
Should only be called from within L{RunTask}. |
|
56 | 58 |
|
57 | 59 |
""" |
58 |
return self.pool.ShouldWorkerTerminate(self) |
|
60 |
self.pool._lock.acquire() |
|
61 |
try: |
|
62 |
assert self._HasRunningTaskUnlocked() |
|
63 |
return self.pool._ShouldWorkerTerminateUnlocked(self) |
|
64 |
finally: |
|
65 |
self.pool._lock.release() |
|
59 | 66 |
|
60 | 67 |
def _HasRunningTaskUnlocked(self): |
61 | 68 |
"""Returns whether this worker is currently running a task. |
... | ... | |
249 | 256 |
""" |
250 | 257 |
return (worker in self._termworkers) |
251 | 258 |
|
252 |
def ShouldWorkerTerminate(self, worker): |
|
253 |
"""Returns whether a worker should terminate. |
|
254 |
|
|
255 |
""" |
|
256 |
self._lock.acquire() |
|
257 |
try: |
|
258 |
return self._ShouldWorkerTerminateUnlocked(worker) |
|
259 |
finally: |
|
260 |
self._lock.release() |
|
261 |
|
|
262 | 259 |
def _HasRunningTasksUnlocked(self): |
263 | 260 |
"""Checks whether there's a task running in a worker. |
264 | 261 |
|
Also available in: Unified diff