From 3289670a04bfee6c62523056fcc7de888a7b59d3 Mon Sep 17 00:00:00 2001 From: Lars Larsson Date: Wed, 4 Nov 2015 17:13:26 +0100 Subject: [PATCH] treat forks config parameter as max value instead of always creating that number of workers --- lib/ansible/executor/task_queue_manager.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ansible/executor/task_queue_manager.py b/lib/ansible/executor/task_queue_manager.py index ae41afb600..f3d278e639 100644 --- a/lib/ansible/executor/task_queue_manager.py +++ b/lib/ansible/executor/task_queue_manager.py @@ -92,8 +92,14 @@ class TaskQueueManager: # plugins for inter-process locking. self._connection_lockfile = tempfile.TemporaryFile() + # Treat "forks" config parameter as max value. Only create number of workers + # equal to number of hosts in inventory if less than max value. + num_workers = self._options.forks + if self._options.forks > len(self._inventory.list_hosts()): + num_workers = len(self._inventory.list_hosts()) + self._workers = [] - for i in range(self._options.forks): + for i in range(num_workers): main_q = multiprocessing.Queue() rslt_q = multiprocessing.Queue() @@ -266,4 +272,3 @@ class TaskQueueManager: method(*args, **kwargs) except Exception as e: self._display.warning('Error when using %s: %s' % (method, str(e))) -