LogPrinterThread.run()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
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
12
    def __init__(self, message_queue, log_printer):
13
        threading.Thread.__init__(self)
14
        self.running = True
15
        self.message_queue = message_queue
16
        self.log_printer = log_printer
17
18
    def run(self):
19
        while self.running:
20
            try:
21
                elem = self.message_queue.get(timeout=0.1)
22
                self.log_printer.log_message(elem)
23
            except queue.Empty:
24
                pass
25