From 2db05c949c4884531abbccadd8e53df0755a6a77 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Wed, 16 Nov 2011 09:11:59 +0100 Subject: [PATCH] workerpool: Use loop to ignore spurious notifications This saves us from returning to the worker code when there is no task to be processed. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/workerpool.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/workerpool.py b/lib/workerpool.py index 4736be5e7..91f213bc2 100644 --- a/lib/workerpool.py +++ b/lib/workerpool.py @@ -354,18 +354,18 @@ class WorkerPool(object): if not self._tasks: logging.debug("Waiting for tasks") - # wait() releases the lock and sleeps until notified - self._pool_to_worker.wait() + while True: + # wait() releases the lock and sleeps until notified + self._pool_to_worker.wait() - logging.debug("Notified while waiting") + logging.debug("Notified while waiting") - # Were we woken up in order to terminate? - if self._ShouldWorkerTerminateUnlocked(worker): - return _TERMINATE + # Were we woken up in order to terminate? + if self._ShouldWorkerTerminateUnlocked(worker): + return _TERMINATE - if not self._tasks: - # Spurious notification, ignore - return None + if self._tasks: + break # Get task from queue and tell pool about it try: -- GitLab