From 47b1315ac72fc103f861b6f511c38de1cd93afcf Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 24 Oct 2012 07:40:31 -0400 Subject: [PATCH] Reinstate Ctrl+C handling --- lib/ansible/runner/__init__.py | 50 +++------------------------------- 1 file changed, 4 insertions(+), 46 deletions(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 61c42afe1c..e3eaf51f37 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -57,29 +57,13 @@ multiprocessing_runner = None ################################################ -def __old__executor_hook(job_queue, result_queue): - ''' callback used by multiprocessing pool ''' - - # attempt workaround of https://github.com/newsapps/beeswithmachineguns/issues/17 - # this function also not present in CentOS 6 - if HAS_ATFORK: - atfork() - - signal.signal(signal.SIGINT, signal.SIG_IGN) - while not job_queue.empty(): - try: - host = job_queue.get(block=False) - result_queue.put(multiprocessing_runner._executor(host)) - except Queue.Empty: - pass - 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() + signal.signal(signal.SIGINT, signal.SIG_IGN) return multiprocessing_runner._executor(host) class HostVars(dict): @@ -579,37 +563,11 @@ class Runner(object): # 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] - result_queue = manager.Queue() - - workers = [] - for i in range(self.forks): - prc = multiprocessing.Process(target=_executor_hook, - args=(job_queue, result_queue)) - prc.start() - workers.append(prc) - try: - for worker in workers: - worker.join() + return p.map(_executor_hook, hosts) except KeyboardInterrupt: - for worker in workers: - worker.terminate() - worker.join() - - results = [] - try: - while not result_queue.empty(): - results.append(result_queue.get(block=False)) - except socket.error: - raise errors.AnsibleError("") - return results - ''' + pool.terminate() + raise errors.AnsibleError("Interrupted") # *****************************************************