From faff20943fa1a983f2d50b7f7646fd04de703c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 5 Jul 2018 10:58:45 +0200 Subject: [PATCH] Capture & log any errors in the state update worker See #2715 --- src/octoprint/printer/standard.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index c1355bbad..ba2d44d4d 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -1305,20 +1305,23 @@ class StateMonitor(object): self._change_event.set() def _work(self): - while True: - self._change_event.wait() + try: + while True: + self._change_event.wait() - now = time.time() - delta = now - self._last_update - additional_wait_time = self._interval - delta - if additional_wait_time > 0: - time.sleep(additional_wait_time) + now = time.time() + delta = now - self._last_update + additional_wait_time = self._interval - delta + if additional_wait_time > 0: + time.sleep(additional_wait_time) - with self._state_lock: - data = self.get_current_data() - self._update_callback(data) - self._last_update = time.time() - self._change_event.clear() + with self._state_lock: + data = self.get_current_data() + self._update_callback(data) + self._last_update = time.time() + self._change_event.clear() + except: + logging.getLogger(__name__).exception("Looks like something crashed inside the state update worker. Please report this on the OctoPrint issue tracker (make sure to include logs!)") def get_current_data(self): with self._progress_lock: