chiark / gitweb /
Merge tag '15.01-RC1' into upstream
[cura.git] / Cura / util / sliceEngine.py
index d1b49ec4442bbaccdf44f680c63386e13da7de7b..e19b1a7413ee630b5c6b0182a96227fe0c27267f 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, pluginInfo.getPostProcessPluginConfig()))
+               self._thread.daemon = True
+               self._thread.start()
+
+       def _runEngine(self, scene, old_thread, pluginConfig):
+               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, pluginInfo.getPostProcessPluginConfig()))
-                       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, pluginConfig):
-               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)