gcode: Don't dump the message log directly from set_printer_ready()

The set_printer_ready() method can be called from a background thread.
Have the main Printer class call a new dump_debug() method in the main
thread on a shutdown event.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-11-30 19:05:25 -05:00
parent 17dcb42752
commit 5ebe8ce025
2 changed files with 12 additions and 6 deletions

View File

@ -72,10 +72,9 @@ class GCodeParser:
self.build_handlers() self.build_handlers()
if is_ready and self.is_fileinput and self.fd_handle is None: if is_ready and self.is_fileinput and self.fd_handle is None:
self.fd_handle = self.reactor.register_fd(self.fd, self.process_data) self.fd_handle = self.reactor.register_fd(self.fd, self.process_data)
if not is_ready: def dump_debug(self):
logging.info("Dumping gcode input %d blocks" % ( logging.info("Dumping gcode input %d blocks" % (
len(self.input_log),)) len(self.input_log),))
# XXX - read from self.input_log is not thread safe
for eventtime, data in self.input_log: for eventtime, data in self.input_log:
logging.info("Read %f: %s" % (eventtime, repr(data))) logging.info("Read %f: %s" % (eventtime, repr(data)))
# Parse input into commands # Parse input into commands

View File

@ -82,6 +82,7 @@ class Printer:
self.connect_timer = self.reactor.register_timer( self.connect_timer = self.reactor.register_timer(
self.connect, self.reactor.NOW) self.connect, self.reactor.NOW)
self.all_config_options = {} self.all_config_options = {}
self.need_dump_debug = False
self.state_message = message_startup self.state_message = message_startup
self.debugoutput = self.dictionary = None self.debugoutput = self.dictionary = None
self.fileconfig = None self.fileconfig = None
@ -91,6 +92,10 @@ class Printer:
self.debugoutput = debugoutput self.debugoutput = debugoutput
self.dictionary = dictionary self.dictionary = dictionary
def stats(self, eventtime): def stats(self, eventtime):
if self.need_dump_debug:
# Call dump_debug here so it is executed in the main thread
self.gcode.dump_debug()
self.need_dump_debug = False
out = [] out = []
out.append(self.gcode.stats(eventtime)) out.append(self.gcode.stats(eventtime))
toolhead = self.objects.get('toolhead') toolhead = self.objects.get('toolhead')
@ -174,6 +179,8 @@ class Printer:
def get_state_message(self): def get_state_message(self):
return self.state_message return self.state_message
def note_shutdown(self, msg): def note_shutdown(self, msg):
if self.state_message == 'Running':
self.need_dump_debug = True
self.state_message = "Firmware shutdown: %s%s" % ( self.state_message = "Firmware shutdown: %s%s" % (
msg, message_shutdown) msg, message_shutdown)
self.gcode.set_printer_ready(False) self.gcode.set_printer_ready(False)