          err = False
          while True:
              try:
                  if self._args.preview:
                      self._do_preview(window_created)
                      cv_key = cv2.waitKey(1000)  # pylint: disable=no-member
                  else:
                      cv_key = None
  
                  if thread.has_error:
                      logger.debug("Thread error detected")
                      err = True
                      break
 
</s> remove         window_created = False
 </s> add  </s> remove                 with self._lock:
                    self._preview_buffer[name] = image
 </s> add                 self._preview.add_image(name, image) </s> remove             if save_iteration or self._save_now or self._refresh_preview:
 </s> add             if self._preview.should_refresh(): </s> remove                 self._toggle_preview_mask = False
                self._refresh_preview = True
 </s> add                 self._preview.request_refresh()
                    self._preview.display_preview()
          err = False
          while True:
              try:
                  if self._args.preview:
                    self._preview.display_preview()
                    self._preview.display_preview()
                    self._preview.display_preview()
                    self._preview.display_preview()
  
                  if thread.has_error:
                      logger.debug("Thread error detected")
                      err = True
                      break
keep keep keep keep replace replace replace replace keep keep keep keep keep
 Live Preview - Replace cv2 with matplotlib viewer 
scripts/train.py