From 9b6b924e9c28b80b3d8fe154917311a22e3c50db Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Sat, 30 Sep 2017 13:27:49 -0500 Subject: [PATCH] Use events instead of sleep for result reading --- lib/ansible/executor/task_queue_manager.py | 2 ++ lib/ansible/plugins/strategy/__init__.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ansible/executor/task_queue_manager.py b/lib/ansible/executor/task_queue_manager.py index 725fc284c9..8dbd215ee0 100644 --- a/lib/ansible/executor/task_queue_manager.py +++ b/lib/ansible/executor/task_queue_manager.py @@ -129,6 +129,7 @@ class TaskQueueManager: self._res_queue = deque() self._res_queue_lock = threading.Lock() + self._res_ready = threading.Event() def _put_in_queue(self, data, queue, lock): lock.acquire() @@ -154,6 +155,7 @@ class TaskQueueManager: def put_result(self, data): self._put_in_queue(data, self._res_queue, self._res_queue_lock) + self._res_ready.set() def get_result(self): return self._pop_off_queue(self._res_queue, self._res_queue_lock) diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index b111e5f4ea..a8195d5190 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -506,7 +506,9 @@ class StrategyBase: results = self._process_pending_results(iterator) ret_results.extend(results) if self._pending_results > 0: - time.sleep(C.DEFAULT_INTERNAL_POLL_INTERVAL) + #time.sleep(C.DEFAULT_INTERNAL_POLL_INTERVAL) + self._tqm._res_ready.wait() + self._tqm._res_ready.clear() display.debug("no more pending results, returning what we have")