From d8407027cfedd40cd969d7d34dee7fc7f9200e03 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Thu, 5 Jul 2018 13:11:28 -0500 Subject: [PATCH] Change TaskManager from is-a to has-a thread As a small stepping stone towards consolidating the shade/sdk/nodepool TaskManager implementations, change TaskManager from being a thread to having a thread. This should allow us to make nodepool's TaskManager inherit from sdk's TaskManager without losing our minds trying to understand how multi-inheritance works with Thread as one of the base classes. Change-Id: Ie89eb9e68e5e3f0a7a55cdd555c683631f305b8e --- nodepool/task_manager.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nodepool/task_manager.py b/nodepool/task_manager.py index 0453d167f..701760ae3 100644 --- a/nodepool/task_manager.py +++ b/nodepool/task_manager.py @@ -62,11 +62,11 @@ class Task(object): self.exception(e, sys.exc_info()[2]) -class TaskManager(threading.Thread): +class TaskManager(object): log = logging.getLogger("nodepool.TaskManager") def __init__(self, client, name, rate): - super(TaskManager, self).__init__(name=name) + super(TaskManager, self).__init__() self.daemon = True self.queue = queue.Queue() self._running = True @@ -74,14 +74,22 @@ class TaskManager(threading.Thread): self.rate = float(rate) self._client = None self.statsd = stats.get_client() + self._thread = threading.Thread(name=name, target=self.run) + self._thread.daemon = True def setClient(self, client): self._client = client + def start(self): + self._thread.start() + def stop(self): self._running = False self.queue.put(None) + def join(self): + self._thread.join() + def run(self): last_ts = 0 try: