From a4af4a704993d15fcadc975c33d0213b656050ba Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Tue, 23 Oct 2012 08:19:15 -0400 Subject: [PATCH] Since we are not needing to pass runner through the multiprocessing queue, just use multiprocessing.pool. Pushing so it can get wider testing. --- lib/ansible/runner/__init__.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index a34824803f1..61c42afe1c6 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -57,7 +57,7 @@ multiprocessing_runner = None ################################################ -def _executor_hook(job_queue, result_queue): +def __old__executor_hook(job_queue, result_queue): ''' callback used by multiprocessing pool ''' # attempt workaround of https://github.com/newsapps/beeswithmachineguns/issues/17 @@ -75,6 +75,13 @@ def _executor_hook(job_queue, result_queue): except: traceback.print_exc() +def _executor_hook(host): + # attempt workaround of https://github.com/newsapps/beeswithmachineguns/issues/17 + # this function also not present in CentOS 6 + if HAS_ATFORK: + atfork() + return multiprocessing_runner._executor(host) + class HostVars(dict): ''' A special view of setup_cache that adds values from the inventory when needed. ''' @@ -567,6 +574,14 @@ class Runner(object): def _parallel_exec(self, hosts): ''' handles mulitprocessing when more than 1 fork is required ''' + # experiment for 0.9, we may revert this if it causes + # problems -- used to cause problems when Runner was a passed + # argument but may not be anymore. + + p = multiprocessing.Pool(self.forks) + return p.map(_executor_hook, hosts) + + OLD_METHOD = ''' manager = multiprocessing.Manager() job_queue = manager.Queue() [job_queue.put(i) for i in hosts] @@ -594,6 +609,7 @@ class Runner(object): except socket.error: raise errors.AnsibleError("") return results + ''' # *****************************************************