1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

moved last utils.debug to display.debug

This commit is contained in:
Brian Coca 2016-04-08 16:00:36 -04:00
parent dd32ba406a
commit 005dc84aa7
6 changed files with 31 additions and 36 deletions

View file

@ -35,7 +35,12 @@ try:
except ImportError: except ImportError:
HAS_ATFORK=False 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'] __all__ = ['ResultProcess']
@ -57,9 +62,9 @@ class ResultProcess(multiprocessing.Process):
super(ResultProcess, self).__init__() super(ResultProcess, self).__init__()
def _send_result(self, result): 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) self._final_q.put(result)
debug("done sending result") display.debug("done sending result")
def _read_worker_result(self): def _read_worker_result(self):
result = None result = None
@ -72,9 +77,9 @@ class ResultProcess(multiprocessing.Process):
try: try:
if not rslt_q.empty(): 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() 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 break
except queue.Empty: except queue.Empty:
pass pass

View file

@ -46,10 +46,14 @@ from ansible.executor.task_result import TaskResult
from ansible.playbook.handler import Handler from ansible.playbook.handler import Handler
from ansible.playbook.task import Task from ansible.playbook.task import Task
from ansible.vars.unsafe_proxy import AnsibleJSONUnsafeDecoder from ansible.vars.unsafe_proxy import AnsibleJSONUnsafeDecoder
from ansible.utils.debug import debug
from ansible.utils.unicode import to_unicode from ansible.utils.unicode import to_unicode
try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()
__all__ = ['WorkerProcess'] __all__ = ['WorkerProcess']
@ -104,7 +108,7 @@ class WorkerProcess(multiprocessing.Process):
try: try:
# execute the task and build a TaskResult from the result # 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( executor_result = TaskExecutor(
self._host, self._host,
self._task, self._task,
@ -116,15 +120,15 @@ class WorkerProcess(multiprocessing.Process):
self._rslt_q self._rslt_q
).run() ).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.vars = dict()
self._host.groups = [] self._host.groups = []
task_result = TaskResult(self._host, self._task, executor_result) task_result = TaskResult(self._host, self._task, executor_result)
# put the result on the result queue # put the result on the result queue
debug("sending task result") display.debug("sending task result")
self._rslt_q.put(task_result) self._rslt_q.put(task_result)
debug("done sending task result") display.debug("done sending task result")
except AnsibleConnectionFailure: except AnsibleConnectionFailure:
self._host.vars = dict() 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='')) 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) self._rslt_q.put(task_result, block=False)
except: except:
debug(u"WORKER EXCEPTION: %s" % to_unicode(e)) display.debug(u"WORKER EXCEPTION: %s" % to_unicode(e))
debug(u"WORKER TRACEBACK: %s" % to_unicode(traceback.format_exc())) display.debug(u"WORKER TRACEBACK: %s" % to_unicode(traceback.format_exc()))
debug("WORKER PROCESS EXITING") display.debug("WORKER PROCESS EXITING")

View file

@ -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.safe_eval import safe_eval
from ansible.template.template import AnsibleJ2Template from ansible.template.template import AnsibleJ2Template
from ansible.template.vars import AnsibleJ2Vars from ansible.template.vars import AnsibleJ2Vars
from ansible.utils.debug import debug
from ansible.utils.unicode import to_unicode, to_str from ansible.utils.unicode import to_unicode, to_str
try: try:
@ -499,7 +498,7 @@ class Templar:
errmsg += "Make sure your variable name does not contain invalid characters like '-': %s" % to_str(te) errmsg += "Make sure your variable name does not contain invalid characters like '-': %s" % to_str(te)
raise AnsibleUndefinedVariable(errmsg) raise AnsibleUndefinedVariable(errmsg)
else: 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))) raise AnsibleError("Unexpected templating type error occurred on (%s): %s" % (to_str(data),to_str(te)))
if preserve_trailing_newlines: if preserve_trailing_newlines:

View file

@ -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()

View file

@ -7,7 +7,10 @@ from multiprocessing import Process, Manager, Pipe, RLock
from ansible.playbook.play import Play from ansible.playbook.play import Play
from ansible.playbook.task import Task 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_WORKERS = 50
NUM_HOSTS = 2500 NUM_HOSTS = 2500

View file

@ -16,7 +16,9 @@ from ansible.executor.task_result import TaskResult
from ansible.parsing.dataloader import DataLoader from ansible.parsing.dataloader import DataLoader
from ansible.vars import VariableManager 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_WORKERS = 20
NUM_HOSTS = 1778 NUM_HOSTS = 1778