chiark / gitweb /
Put the runEngine code inside the thread to prevent this code from blocking the GUI...
authordaid <daid303@gmail.com>
Tue, 9 Dec 2014 18:11:05 +0000 (19:11 +0100)
committerdaid <daid303@gmail.com>
Tue, 9 Dec 2014 18:11:05 +0000 (19:11 +0100)
Cura/util/sliceEngine.py

index d7750ca05edb94745c9bc28769a598f85b57f274..2678c69f831bf8eaf33f242a5e7f2d35a4e3aa4d 100644 (file)
@@ -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)