From 005dc84aa744c1cb71995d4f554fb946c19d1bc6 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 8 Apr 2016 16:00:36 -0400 Subject: [PATCH] moved last utils.debug to display.debug --- lib/ansible/executor/process/result.py | 15 ++++++++++----- lib/ansible/executor/process/worker.py | 22 +++++++++++++--------- lib/ansible/template/__init__.py | 3 +-- lib/ansible/utils/debug.py | 18 ------------------ samples/multi.py | 5 ++++- samples/multi_queues.py | 4 +++- 6 files changed, 31 insertions(+), 36 deletions(-) delete mode 100644 lib/ansible/utils/debug.py diff --git a/lib/ansible/executor/process/result.py b/lib/ansible/executor/process/result.py index 1fbcbeb8960..fce31db4942 100644 --- a/lib/ansible/executor/process/result.py +++ b/lib/ansible/executor/process/result.py @@ -35,7 +35,12 @@ try: except ImportError: HAS_ATFORK=False -from ansible.utils.debug import debug +try: + from __main__ import display +except ImportError: + from ansible.utils.display import Display + display = Display() + __all__ = ['ResultProcess'] @@ -57,9 +62,9 @@ class ResultProcess(multiprocessing.Process): super(ResultProcess, self).__init__() def _send_result(self, result): - debug(u"sending result: %s" % ([text_type(x) for x in result],)) + display.debug(u"sending result: %s" % ([text_type(x) for x in result],)) self._final_q.put(result) - debug("done sending result") + display.debug("done sending result") def _read_worker_result(self): result = None @@ -72,9 +77,9 @@ class ResultProcess(multiprocessing.Process): try: if not rslt_q.empty(): - debug("worker %d has data to read" % self._cur_worker) + display.debug("worker %d has data to read" % self._cur_worker) result = rslt_q.get() - debug("got a result from worker %d: %s" % (self._cur_worker, result)) + display.debug("got a result from worker %d: %s" % (self._cur_worker, result)) break except queue.Empty: pass diff --git a/lib/ansible/executor/process/worker.py b/lib/ansible/executor/process/worker.py index 7aa355aab8c..ce5de460a10 100644 --- a/lib/ansible/executor/process/worker.py +++ b/lib/ansible/executor/process/worker.py @@ -46,10 +46,14 @@ from ansible.executor.task_result import TaskResult from ansible.playbook.handler import Handler from ansible.playbook.task import Task from ansible.vars.unsafe_proxy import AnsibleJSONUnsafeDecoder - -from ansible.utils.debug import debug from ansible.utils.unicode import to_unicode +try: + from __main__ import display +except ImportError: + from ansible.utils.display import Display + display = Display() + __all__ = ['WorkerProcess'] @@ -104,7 +108,7 @@ class WorkerProcess(multiprocessing.Process): try: # execute the task and build a TaskResult from the result - debug("running TaskExecutor() for %s/%s" % (self._host, self._task)) + display.debug("running TaskExecutor() for %s/%s" % (self._host, self._task)) executor_result = TaskExecutor( self._host, self._task, @@ -116,15 +120,15 @@ class WorkerProcess(multiprocessing.Process): self._rslt_q ).run() - debug("done running TaskExecutor() for %s/%s" % (self._host, self._task)) + display.debug("done running TaskExecutor() for %s/%s" % (self._host, self._task)) self._host.vars = dict() self._host.groups = [] task_result = TaskResult(self._host, self._task, executor_result) # put the result on the result queue - debug("sending task result") + display.debug("sending task result") self._rslt_q.put(task_result) - debug("done sending task result") + display.debug("done sending task result") except AnsibleConnectionFailure: self._host.vars = dict() @@ -140,8 +144,8 @@ class WorkerProcess(multiprocessing.Process): task_result = TaskResult(self._host, self._task, dict(failed=True, exception=to_unicode(traceback.format_exc()), stdout='')) self._rslt_q.put(task_result, block=False) except: - debug(u"WORKER EXCEPTION: %s" % to_unicode(e)) - debug(u"WORKER TRACEBACK: %s" % to_unicode(traceback.format_exc())) + display.debug(u"WORKER EXCEPTION: %s" % to_unicode(e)) + display.debug(u"WORKER TRACEBACK: %s" % to_unicode(traceback.format_exc())) - debug("WORKER PROCESS EXITING") + display.debug("WORKER PROCESS EXITING") diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index b91833dee4c..4e1f7b7fd8b 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -39,7 +39,6 @@ from ansible.plugins import filter_loader, lookup_loader, test_loader from ansible.template.safe_eval import safe_eval from ansible.template.template import AnsibleJ2Template from ansible.template.vars import AnsibleJ2Vars -from ansible.utils.debug import debug from ansible.utils.unicode import to_unicode, to_str try: @@ -499,7 +498,7 @@ class Templar: errmsg += "Make sure your variable name does not contain invalid characters like '-': %s" % to_str(te) raise AnsibleUndefinedVariable(errmsg) else: - debug("failing because of a type error, template data is: %s" % to_str(data)) + display.debug("failing because of a type error, template data is: %s" % to_str(data)) raise AnsibleError("Unexpected templating type error occurred on (%s): %s" % (to_str(data),to_str(te))) if preserve_trailing_newlines: diff --git a/lib/ansible/utils/debug.py b/lib/ansible/utils/debug.py deleted file mode 100644 index 5b04ac05726..00000000000 --- a/lib/ansible/utils/debug.py +++ /dev/null @@ -1,18 +0,0 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -import os -import time -import sys - -from multiprocessing import Lock - -from ansible import constants as C - -global_debug_lock = Lock() -def debug(msg): - if C.DEFAULT_DEBUG: - global_debug_lock.acquire() - print("%6d %0.5f: %s" % (os.getpid(), time.time(), msg)) - sys.stdout.flush() - global_debug_lock.release() diff --git a/samples/multi.py b/samples/multi.py index dce61430594..ab82fe2ecd4 100644 --- a/samples/multi.py +++ b/samples/multi.py @@ -7,7 +7,10 @@ from multiprocessing import Process, Manager, Pipe, RLock from ansible.playbook.play import Play from ansible.playbook.task import Task -from ansible.utils.debug import debug + +from ansible.utils.display import Display +display = Display() +debug = display.debug NUM_WORKERS = 50 NUM_HOSTS = 2500 diff --git a/samples/multi_queues.py b/samples/multi_queues.py index 3b647071c71..52015702b21 100644 --- a/samples/multi_queues.py +++ b/samples/multi_queues.py @@ -16,7 +16,9 @@ from ansible.executor.task_result import TaskResult from ansible.parsing.dataloader import DataLoader from ansible.vars import VariableManager -from ansible.utils.debug import debug +from ansible.utils.display import Display +display = Display() +debug = display.debug NUM_WORKERS = 20 NUM_HOSTS = 1778