import logging class QueueHandler(logging.Handler): """Class to send logging records to a queue It can be used from different threads The ConsoleUi class polls this queue to display records in a ScrolledText widget """ # Example from Moshe Kaplan: https://gist.github.com/moshekaplan/c425f861de7bbf28ef06 # (https://stackoverflow.com/questions/13318742/python-logging-to-tkinter-text-widget) is not thread safe! # See https://stackoverflow.com/questions/43909849/tkinter-python-crashes-on-new-thread-trying-to-log-on-main-thread def __init__(self, log_queue): super().__init__() self.log_queue = log_queue def emit(self, record): self.log_queue.put(record)