From: Justin Nesselrotte Date: Sat, 20 Dec 2014 20:01:11 +0000 (-0600) Subject: Modifying serial communication to use a thread X-Git-Tag: 14.09-1.18~18^2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=2aa03de4ea55110d3cef30ee2d39201b8cc48707;p=cura.git Modifying serial communication to use a thread This helps with the application not responding, with closing the application without an error (Since it now seems to free the serial port correctly), and with overall startup cost for the connecting process. --- diff --git a/Cura/serialCommunication.py b/Cura/serialCommunication.py index c1ec18dc..cf6a0aec 100644 --- a/Cura/serialCommunication.py +++ b/Cura/serialCommunication.py @@ -8,6 +8,7 @@ And handles all communication with the initial process. __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License" import sys +import threading import time import os import json @@ -46,8 +47,8 @@ class serialComm(object): def mcProgress(self, lineNr): sys.stdout.write('progress:%d\n' % (lineNr)) - #def mcZChange(self, newZ): - # sys.stdout.write('changeZ:%d\n' % (newZ)) + def mcZChange(self, newZ): + pass def monitorStdin(self): while not self._comm.isClosed(): @@ -68,7 +69,10 @@ class serialComm(object): def startMonitor(portName, baudrate): sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) comm = serialComm(portName, baudrate) - comm.monitorStdin() + thread = threading.Thread(target=comm.monitorStdin) + thread.start() + while thread.is_alive(): + time.sleep(0) def main(): if len(sys.argv) != 3: