diff options
author | daid <daid303@gmail.com> | 2014-12-09 21:11:05 +0300 |
---|---|---|
committer | daid <daid303@gmail.com> | 2014-12-09 21:11:05 +0300 |
commit | 5d857c5872c919510e608a182feac7e37c01259a (patch) | |
tree | 6a7cb50c538f57e77b6f8fe0e9deb57b4b75696e | |
parent | af833610f878f71c7b0a36b34febfc70ae82ed46 (diff) |
Put the runEngine code inside the thread to prevent this code from blocking the GUI on high poly 3D models.
-rw-r--r-- | Cura/util/sliceEngine.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/Cura/util/sliceEngine.py b/Cura/util/sliceEngine.py index d7750ca05e..2678c69f83 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) |