🐛 Fix a potential race condition
If the comm layer starts sending state changes (e.g. to auto detect) before the constructor returns, self._comm in the printer interface is still None and thus states can't be decoded. Probably part of #3653
This commit is contained in:
1 parent
6083943e03
commit
9dd1e95eae
2 files changed
+7
-1
No files matched your search
@@ -267,6 +267,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
logging.getLogger("SERIAL").info("serial.log is currently not enabled, you can enable it via Settings > Serial Connection > Log communication to serial.log")
|
||||
|
||||
self._comm = comm.MachineCom(port, baudrate, callbackObject=self, printerProfileManager=self._printerProfileManager)
|
||||
self._comm.start()
|
||||
|
||||
def disconnect(self, *args, **kwargs):
|
||||
"""
|
||||
|
||||
@@ -648,12 +648,17 @@ class MachineCom(object):
|
||||
self._monitoring_active = True
|
||||
self.monitoring_thread = threading.Thread(target=self._monitor, name="comm._monitor")
|
||||
self.monitoring_thread.daemon = True
|
||||
self.monitoring_thread.start()
|
||||
|
||||
# sending thread
|
||||
self._send_queue_active = True
|
||||
self.sending_thread = threading.Thread(target=self._send_loop, name="comm.sending_thread")
|
||||
self.sending_thread.daemon = True
|
||||
|
||||
def start(self):
|
||||
# doing this here instead of __init__ combats a race condition where
|
||||
# self._comm in the printer interface is still None on first pushs from
|
||||
# the comm layer during detection
|
||||
self.monitoring_thread.start()
|
||||
self.sending_thread.start()
|
||||
|
||||
def __del__(self):
|
||||
|
||||
Reference in new issue
Block a user