Failed Conditions
Pull Request — master (#1152)
by Lasse
03:36
created

coalib.processes.LogPrinterThread   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %
Metric Value
dl 0
loc 19
rs 10
wmc 4
1
import queue
2
import threading
3
4
5
class LogPrinterThread(threading.Thread):
6
    """
7
    This is the Thread object that outputs all log messages it gets from
8
    its message_queue. Setting obj.running = False will stop within the next
9
    0.1 seconds.
10
    """
11
    def __init__(self, message_queue, log_printer):
12
        threading.Thread.__init__(self)
13
        self.running = True
14
        self.message_queue = message_queue
15
        self.log_printer = log_printer
16
17
    def run(self):
18
        while self.running:
19
            try:
20
                elem = self.message_queue.get(timeout=0.1)
21
                self.log_printer.log_message(elem)
22
            except queue.Empty:
23
                pass
24