def patch_async_emit(handler: Handler): base_emit = handler.emit queue = Queue() def loop(): while True: record = queue.get() try: base_emit(record) except: print(sys.exc_info()) def async_emit(record): queue.put(record) thread = Thread(target=loop) thread.daemon = True thread.start() handler.emit = async_emit return handler
def _bind(self): root = getLogger() handler = Handler() handler.emit = self._messages.emit root.addHandler(handler)