Commit a2201f96 by fwkz

Adding current thread information to PrintResource

parent b3a1fe26
...@@ -46,6 +46,6 @@ class PrinterThread(threading.Thread): ...@@ -46,6 +46,6 @@ class PrinterThread(threading.Thread):
def run(self): def run(self):
while True: while True:
content, sep, end, file_ = printer_queue.get() content, sep, end, file_, thread = printer_queue.get()
print(*content, sep=sep, end=end, file=file_) print(*content, sep=sep, end=end, file=file_)
printer_queue.task_done() printer_queue.task_done()
...@@ -40,7 +40,7 @@ colors = { ...@@ -40,7 +40,7 @@ colors = {
requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning) requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
Resource = collections.namedtuple("Resource", ["name", "template_path", "context"]) Resource = collections.namedtuple("Resource", ["name", "template_path", "context"])
PrintResource = collections.namedtuple("PrintResource", ['content', 'sep', 'end', 'file',]) PrintResource = collections.namedtuple("PrintResource", ['content', 'sep', 'end', 'file', 'thread'])
def index_modules(modules_directory=MODULES_DIR): def index_modules(modules_directory=MODULES_DIR):
...@@ -231,12 +231,13 @@ def __cprint(*args, **kwargs): ...@@ -231,12 +231,13 @@ def __cprint(*args, **kwargs):
file_ = kwargs.get('file', sys.stdout) file_ = kwargs.get('file', sys.stdout)
sep = kwargs.get('sep', ' ') sep = kwargs.get('sep', ' ')
end = kwargs.get('end', '\n') end = kwargs.get('end', '\n')
thread = threading.current_thread()
if color: if color:
printer_queue.put(PrintResource(content='\033[{}m'.format(colors[color]), end='', file=file_, sep=sep)) printer_queue.put(PrintResource(content='\033[{}m'.format(colors[color]), end='', file=file_, sep=sep, thread=thread))
printer_queue.put(PrintResource(content=args, end='', file=file_, sep=sep)) # TODO printing text that starts from newline printer_queue.put(PrintResource(content=args, end='', file=file_, sep=sep, thread=thread)) # TODO printing text that starts from newline
printer_queue.put(PrintResource(content='\033[0m', sep=sep, end=end, file=file_)) printer_queue.put(PrintResource(content='\033[0m', sep=sep, end=end, file=file_, thread=thread))
else: else:
printer_queue.put(PrintResource(content=args, sep=sep, end=end, file=file_)) printer_queue.put(PrintResource(content=args, sep=sep, end=end, file=file_, thread=thread))
def print_error(*args, **kwargs): def print_error(*args, **kwargs):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment