Commit 2f4e1516 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

workerpool: Additional check in BaseWorker.ShouldTerminate



Document that it should only be called from within RunTask and
add an assertion for this. This means we can no longer use a
method on the pool and hence remove WorkerPool.ShouldWorkerTerminate.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent ccedb11b
......@@ -52,10 +52,17 @@ class BaseWorker(threading.Thread, object):
self._current_task = None
def ShouldTerminate(self):
"""Returns whether a worker should terminate.
"""Returns whether this worker should terminate.
Should only be called from within L{RunTask}.
"""
return self.pool.ShouldWorkerTerminate(self)
self.pool._lock.acquire()
try:
assert self._HasRunningTaskUnlocked()
return self.pool._ShouldWorkerTerminateUnlocked(self)
finally:
self.pool._lock.release()
def _HasRunningTaskUnlocked(self):
"""Returns whether this worker is currently running a task.
......@@ -249,16 +256,6 @@ class WorkerPool(object):
"""
return (worker in self._termworkers)
def ShouldWorkerTerminate(self, worker):
"""Returns whether a worker should terminate.
"""
self._lock.acquire()
try:
return self._ShouldWorkerTerminateUnlocked(worker)
finally:
self._lock.release()
def _HasRunningTasksUnlocked(self):
"""Checks whether there's a task running in a worker.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment