From ad8c275887086fb3d8534852a9285160f7c6eb29 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Fri, 7 Feb 2014 20:38:18 -0500 Subject: [PATCH] Revert "While the previous work on the foon class can't be quite recycled, it's still a nice abstraction." This reverts commit caab52aee25e8163d0cb8add4df3d49a803f52d1. --- lib/ansible/runner/__init__.py | 8 ++++---- lib/ansible/runner/foon.py | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 0fe8e599d94..9160a0b5928 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -63,6 +63,7 @@ PROCESS_LOCKFILE = tempfile.TemporaryFile() from foon import Foon +FOON = Foon() ################################################ @@ -1057,10 +1058,11 @@ class Runner(object): # ***************************************************** - def _parallel_exec(self, params): + def _parallel_exec(self, hosts): ''' handles mulitprocessing when more than 1 fork is required ''' - return self.foon.map(_executor_hook, params) + FOON.set_size(self.forks) + return FOON.map(_executor_hook, hosts) # ***************************************************** @@ -1112,8 +1114,6 @@ class Runner(object): if self.forks == 0 or self.forks > len(hosts): self.forks = len(hosts) - self.foon = Foon(self.forks) - if p and getattr(p, 'BYPASS_HOST_LOOP', None): # Expose the current hostgroup to the bypassing plugins diff --git a/lib/ansible/runner/foon.py b/lib/ansible/runner/foon.py index f5f3be12204..f084ba726e2 100644 --- a/lib/ansible/runner/foon.py +++ b/lib/ansible/runner/foon.py @@ -99,18 +99,30 @@ class MyPool(mpool.Pool): class Foon(object): - def __init__(self, size): - self.pool = self._make_pool(size) + def __init__(self): + self.set_size(0) - def _make_pool(self, processes=None, initializer=None, initargs=()): + def make_pool(self, processes=None, initializer=None, initargs=()): ''' Returns a process pool object ''' return MyPool(processes, initializer, initargs) + def set_size(self, size): + + global OLD_SIZE + global POOL + + if size > OLD_SIZE or POOL is None: + OLD_SIZE = size + POOL = self.make_pool() + + def map(self, function, data_list): + + global POOL try: - return self.pool.map(function, data_list) + return POOL.map(function, data_list) except KeyboardInterrupt: print "KEYBOARD INTERRUPT!" sys.exit(1)