1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Sleep briefly while waiting for pending results to reduce CPU churn

This commit is contained in:
James Cammarata 2016-10-06 08:49:47 -05:00
parent 087fb4265f
commit e26bce5221

View file

@ -71,14 +71,12 @@ class SharedPluginLoaderObj:
_sentinel = object() _sentinel = object()
def results_thread_main(strategy): def results_thread_main(strategy):
#print("RESULT THREAD STARTING: %s" % threading.current_thread())
while True: while True:
try: try:
result = strategy._final_q.get() result = strategy._final_q.get()
if type(result) == object: if type(result) == object:
break break
else: else:
#print("result in thread is: %s" % result._result)
strategy._results_lock.acquire() strategy._results_lock.acquire()
strategy._results.append(result) strategy._results.append(result)
strategy._results_lock.release() strategy._results_lock.release()
@ -86,7 +84,6 @@ def results_thread_main(strategy):
break break
except Queue.Empty: except Queue.Empty:
pass pass
#print("RESULT THREAD EXITED: %s" % threading.current_thread())
class StrategyBase: class StrategyBase:
@ -121,7 +118,7 @@ class StrategyBase:
self._results = deque() self._results = deque()
self._results_lock = threading.Condition(threading.Lock()) self._results_lock = threading.Condition(threading.Lock())
#print("creating thread for strategy %s" % id(self)) # create the result processing thread for reading results in the background
self._results_thread = threading.Thread(target=results_thread_main, args=(self,)) self._results_thread = threading.Thread(target=results_thread_main, args=(self,))
self._results_thread.daemon = True self._results_thread.daemon = True
self._results_thread.start() self._results_thread.start()
@ -316,7 +313,6 @@ class StrategyBase:
continue continue
if original_task.register: if original_task.register:
#print("^ REGISTERING RESULT %s" % original_task.register)
if original_task.run_once: if original_task.run_once:
host_list = [host for host in self._inventory.get_hosts(iterator._play.hosts) if host.name not in self._tqm._unreachable_hosts] host_list = [host for host in self._inventory.get_hosts(iterator._play.hosts) if host.name not in self._tqm._unreachable_hosts]
else: else:
@ -533,6 +529,8 @@ class StrategyBase:
results = self._process_pending_results(iterator) results = self._process_pending_results(iterator)
ret_results.extend(results) ret_results.extend(results)
if self._pending_results > 0:
time.sleep(0.001)
display.debug("no more pending results, returning what we have") display.debug("no more pending results, returning what we have")