From: daid Date: Tue, 9 Dec 2014 18:11:05 +0000 (+0100) Subject: Put the runEngine code inside the thread to prevent this code from blocking the GUI... X-Git-Tag: 15.01-RC1~1 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5d857c5872c919510e608a182feac7e37c01259a;p=cura.git Put the runEngine code inside the thread to prevent this code from blocking the GUI on high poly 3D models. --- diff --git a/Cura/util/sliceEngine.py b/Cura/util/sliceEngine.py index d7750ca0..2678c69f 100644 --- a/Cura/util/sliceEngine.py +++ b/Cura/util/sliceEngine.py @@ -287,6 +287,17 @@ class Engine(object): def runEngine(self, scene): if len(scene.objects()) < 1: return + self._thread = threading.Thread(target=self._runEngine, args=(scene, self._thread)) + self._thread.daemon = True + self._thread.start() + + def _runEngine(self, scene, old_thread): + if old_thread is not None: + if self._process is not None: + self._process.terminate() + old_thread.join() + self._callback(-1.0) + extruderCount = 1 for obj in scene.objects(): if scene.checkPlatform(obj): @@ -358,25 +369,17 @@ class Engine(object): commandList += ['$' * len(obj._meshList)] self._objCount += 1 modelHash = hash.hexdigest() - if self._objCount > 0: - self._thread = threading.Thread(target=self._watchProcess, args=(commandList, self._thread, engineModelData, modelHash)) - self._thread.daemon = True - self._thread.start() + if self._objCount < 1: + return + if self._thread != threading.currentThread(): + return - def _watchProcess(self, commandList, oldThread, engineModelData, modelHash): - if oldThread is not None: - if self._process is not None: - self._process.terminate() - oldThread.join() - self._callback(-1.0) self._modelData = engineModelData try: self._process = self._runEngineProcess(commandList) except OSError: traceback.print_exc() return - if self._thread != threading.currentThread(): - self._process.terminate() self._result = EngineResult() self._result.addLog('Running: %s' % (' '.join(commandList))) @@ -390,6 +393,8 @@ class Engine(object): try: data = self._process.stdout.read(4096) while len(data) > 0: + if self._thread != threading.currentThread(): + self._process.terminate() self._result._gcodeData.write(data) data = self._process.stdout.read(4096)