def start_console_logger(self, log_fifo): """ Start a thread that monitors the microVM console. The console output will be redirected to the log file. """ def monitor_fd(microvm, path): try: fd = open(path, "r") while True: if microvm.logging_thread.stopped(): return data = fd.readline() if data: microvm.append_to_log_data(data) except IOError as error: LOG.error("[%s] IOError while monitoring fd:" " %s", microvm.id, error) microvm.append_to_log_data(str(error)) return self.logging_thread = utils.StoppableThread( target=monitor_fd, args=(self, log_fifo.path), daemon=True) self.logging_thread.start()
def start_console_logger(self, log_fifo): """ Start a thread that monitors the microVM console. The console output will be redirected to the log file. """ def monitor_fd(microvm, path): try: fd = open(path, "r") while True: try: if microvm().logging_thread.stopped(): return data = fd.readline() if data: microvm().append_to_log_data(data) except AttributeError as _: # This means that the microvm object was destroyed and # we are using a None reference. return except IOError as error: # pylint: disable=W0150 try: LOG.error("[%s] IOError while monitoring fd:" " %s", microvm().id, error) microvm().append_to_log_data(str(error)) except AttributeError as _: # This means that the microvm object was destroyed and # we are using a None reference. pass finally: return self.logging_thread = utils.StoppableThread(target=monitor_fd, args=(weakref.ref(self), log_fifo.path), daemon=True) self.logging_thread.start()