                  if self.stop:
                      logger.debug("Stop received")
                      break
                  if keypress.kbhit():
                      key = keypress.getch()
                      if key in ("\n", "\r"):
                          logger.debug("Exit requested")
                          break
                      if key in ("s", "S"):
                          logger.info("Save requested")
                          self.save_now = True
 
</s> remove                     if key in ("s", "S"):
 </s> add                     if console_key in ("s", "S"): </s> remove                 sleep(1)
 </s> add                 if not is_preview:
                    sleep(1) </s> remove     def monitor_preview(self, thread):
        """ Generate the preview window and wait for keyboard input """
        logger.debug("Launching Preview Monitor")
        logger.info("R|=====================================================================")
        logger.info("R|- Using live preview                                                -")
        logger.info("R|- Press 'ENTER' on the preview window to save and quit              -")
        logger.info("R|- Press 'S' on the preview window to save model weights immediately -")
        logger.info("R|=====================================================================")
        err = False
        while True:
            try:
                with self.lock:
                    for name, image in self.preview_buffer.items():
                        cv2.imshow(name, image)  # pylint: disable=no-member

                key = cv2.waitKey(1000)  # pylint: disable=no-member
                if self.stop:
                    logger.debug("Stop received")
                    break
                if thread.has_error:
                    logger.debug("Thread error detected")
                    err = True
                    break
                if key == ord("\n") or key == ord("\r"):
                    logger.debug("Exit requested")
                    break
                if key == ord("s"):
                    logger.info("Save requested")
                    self.save_now = True
            except KeyboardInterrupt:
                logger.debug("Keyboard Interrupt received")
                break
        logger.debug("Closed Preview Monitor")
        return err

    def monitor_console(self, thread):
        """ Monitor the console
            NB: A custom function needs to be used for this because
                input() blocks """
        logger.debug("Launching Console Monitor")
 </s> add     def monitor(self, thread):
        """ Monitor the console, and generate + monitor preview if requested """
        is_preview = self.args.preview
        logger.debug("Launching Monitor")
                    console_key = keypress.getch()
                    if console_key in ("\n", "\r"):
                  if self.stop:
                      logger.debug("Stop received")
                      break
                  if keypress.kbhit():
                    console_key = keypress.getch()
                    if console_key in ("\n", "\r"):
                    console_key = keypress.getch()
                    if console_key in ("\n", "\r"):
                          logger.debug("Exit requested")
                          break
                      if key in ("s", "S"):
                          logger.info("Save requested")
                          self.save_now = True
keep keep keep keep replace replace keep keep keep keep keep
 Merge Extract Monitors. Correctly exit GUI when terminating training with preview window open 
scripts/train.py