klippy: Do not start stats timer until after connect completes

Generating stats during connect leads to potential use of not yet
initialized variables.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-09-19 17:12:04 -04:00
parent 123719bf92
commit f1c2f789b6
1 changed files with 3 additions and 7 deletions

View File

@ -190,31 +190,27 @@ class Printer:
"Unknown option '%s' in section '%s'" % ( "Unknown option '%s' in section '%s'" % (
option, section)) option, section))
def _connect(self, eventtime): def _connect(self, eventtime):
self.reactor.unregister_timer(self.connect_timer)
try: try:
self._load_config() self._load_config()
if self.start_args.get('debugoutput') is None:
self.reactor.update_timer(self.stats_timer, self.reactor.NOW)
self.mcu.connect() self.mcu.connect()
self.gcode.set_printer_ready(True) self.gcode.set_printer_ready(True)
self.state_message = message_ready self.state_message = message_ready
if self.start_args.get('debugoutput') is None:
self.reactor.update_timer(self.stats_timer, self.reactor.NOW)
except (self.config_error, pins.error) as e: except (self.config_error, pins.error) as e:
logging.exception("Config error") logging.exception("Config error")
self.state_message = "%s%s" % (str(e), message_restart) self.state_message = "%s%s" % (str(e), message_restart)
self.reactor.update_timer(self.stats_timer, self.reactor.NEVER)
except msgproto.error as e: except msgproto.error as e:
logging.exception("Protocol error") logging.exception("Protocol error")
self.state_message = "%s%s" % (str(e), message_protocol_error) self.state_message = "%s%s" % (str(e), message_protocol_error)
self.reactor.update_timer(self.stats_timer, self.reactor.NEVER)
except mcu.error as e: except mcu.error as e:
logging.exception("MCU error during connect") logging.exception("MCU error during connect")
self.state_message = "%s%s" % (str(e), message_mcu_connect_error) self.state_message = "%s%s" % (str(e), message_mcu_connect_error)
self.reactor.update_timer(self.stats_timer, self.reactor.NEVER)
except: except:
logging.exception("Unhandled exception during connect") logging.exception("Unhandled exception during connect")
self.state_message = "Internal error during connect.%s" % ( self.state_message = "Internal error during connect.%s" % (
message_restart,) message_restart,)
self.reactor.update_timer(self.stats_timer, self.reactor.NEVER)
self.reactor.unregister_timer(self.connect_timer)
return self.reactor.NEVER return self.reactor.NEVER
def run(self): def run(self):
systime = time.time() systime = time.time()