From 50196c7141d28622794b92c0b4445ad08f01262e Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 2 Sep 2018 12:43:40 -0400 Subject: [PATCH] klippy: Use reactor register_callback() mechanism Signed-off-by: Kevin O'Connor --- klippy/klippy.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/klippy/klippy.py b/klippy/klippy.py index 2b98fda6..d3fedf10 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -136,11 +136,9 @@ class Printer: gc = gcode.GCodeParser(self, input_fd) self.objects = collections.OrderedDict({'gcode': gc}) self.stats_timer = self.reactor.register_timer(self._stats) - self.connect_timer = self.reactor.register_timer( - self._connect, self.reactor.NOW) + self.reactor.register_callback(self._connect) self.state_message = message_startup self.is_shutdown = False - self.async_shutdown_msg = "" self.run_result = None self.stats_cb = [] self.state_cb = [] @@ -238,7 +236,6 @@ class Printer: self.state_cb = [o.printer_state for o in self.objects.values() if hasattr(o, 'printer_state')] def _connect(self, eventtime): - self.reactor.unregister_timer(self.connect_timer) try: self._read_config() for cb in self.state_cb: @@ -281,9 +278,6 @@ class Printer: # Check restart flags run_result = self.run_result try: - if run_result == 'shutdown': - self.invoke_shutdown(self.async_shutdown_msg) - continue self._stats(self.reactor.monotonic(), force_output=True) if run_result == 'firmware_restart': for m in self.lookup_module_objects('mcu'): @@ -301,8 +295,8 @@ class Printer: for cb in self.state_cb: cb('shutdown') def invoke_async_shutdown(self, msg): - self.async_shutdown_msg = msg - self.request_exit("shutdown") + self.reactor.register_async_callback( + (lambda e: self.invoke_shutdown(msg))) def request_exit(self, result): self.run_result = result self.reactor.end()