From f7ebb6c7fa8a077e6ac8a089e2ebaa99809eeb82 Mon Sep 17 00:00:00 2001 From: daid Date: Tue, 2 Dec 2014 11:00:56 +0100 Subject: [PATCH] Improve error logging on out of memory. Improve plugin handling memory. --- Cura/util/bigDataStorage.py | 1 + Cura/util/pluginInfo.py | 9 ++++++++- Cura/util/sliceEngine.py | 38 ++++++++++++++++++++----------------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Cura/util/bigDataStorage.py b/Cura/util/bigDataStorage.py index 7b469cf3..28362bf6 100644 --- a/Cura/util/bigDataStorage.py +++ b/Cura/util/bigDataStorage.py @@ -1,3 +1,4 @@ +import sys import cStringIO as StringIO class BigDataStorage(object): diff --git a/Cura/util/pluginInfo.py b/Cura/util/pluginInfo.py index c881bf88..eba3770b 100644 --- a/Cura/util/pluginInfo.py +++ b/Cura/util/pluginInfo.py @@ -136,6 +136,7 @@ def runPostProcessingPlugins(engineResult): break f.write(data) f.close() + del gcode locals = {'filename': tempfilename} for param in plugin.getParams(): @@ -157,7 +158,13 @@ def runPostProcessingPlugins(engineResult): return "%s: '%s' @ %s:%s:%d" % (str(sys.exc_info()[0].__name__), str(sys.exc_info()[1]), os.path.basename(locationInfo[0]), locationInfo[2], locationInfo[1]) if tempfilename is not None: f = open(tempfilename, "r") - engineResult.setGCode(f.read()) + engineResult.setGCode("") + import gc + gc.collect() + data = f.read(4096) + while len(data) > 0: + engineResult._gcodeData.write(data) + data = f.read(4096) f.close() os.unlink(tempfilename) return None diff --git a/Cura/util/sliceEngine.py b/Cura/util/sliceEngine.py index 8d57910a..e6d7653c 100644 --- a/Cura/util/sliceEngine.py +++ b/Cura/util/sliceEngine.py @@ -385,25 +385,29 @@ class Engine(object): logThread.daemon = True logThread.start() - data = self._process.stdout.read(4096) - while len(data) > 0: - self._result._gcodeData.write(data) + try: data = self._process.stdout.read(4096) - - returnCode = self._process.wait() - logThread.join() - if returnCode == 0: - pluginError = pluginInfo.runPostProcessingPlugins(self._result) - if pluginError is not None: - print pluginError - self._result.addLog(pluginError) - self._result.setFinished(True) - self._callback(1.0) - else: - for line in self._result.getLog(): - print line + while len(data) > 0: + self._result._gcodeData.write(data) + data = self._process.stdout.read(4096) + + returnCode = self._process.wait() + logThread.join() + if returnCode == 0: + self._result.setFinished(True) + plugin_error = pluginInfo.runPostProcessingPlugins(self._result) + if plugin_error is not None: + print plugin_error + self._result.addLog(plugin_error) + self._callback(1.0) + else: + for line in self._result.getLog(): + print line + self._callback(-1.0) + self._process = None + except MemoryError: + self._result.addLog("MemoryError") self._callback(-1.0) - self._process = None def _watchStderr(self, stderr): objectNr = 0 -- 2.30.2