From d04e6a664417108141ae9fae319c037588d468a1 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Tue, 11 Oct 2016 13:34:48 +0200 Subject: [PATCH] Use buffered writing for writing gcode to removable drives GCode files are still written line by line, but python is instructed to use buffering. This greatly decreases the total time required to write large(ish) files to USB drives, while having minimal impact on memory use. CURA-2544 --- .../RemovableDriveOutputDevice.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py b/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py index efb7929327..b7d31e68f8 100644 --- a/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py +++ b/plugins/RemovableDriveOutputDevice/RemovableDriveOutputDevice.py @@ -23,6 +23,7 @@ class RemovableDriveOutputDevice(OutputDevice): self.setPriority(1) self._writing = False + self._stream = None def requestWrite(self, node, file_name = None, filter_by_machine = False): filter_by_machine = True # This plugin is indended to be used by machine (regardless of what it was told to do) @@ -65,8 +66,8 @@ class RemovableDriveOutputDevice(OutputDevice): try: Logger.log("d", "Writing to %s", file_name) - stream = open(file_name, "wt") - job = WriteMeshJob(writer, stream, node, MeshWriter.OutputMode.TextMode) + self._stream = open(file_name, "wt", buffering = 1) + job = WriteMeshJob(writer, self._stream, node, MeshWriter.OutputMode.TextMode) job.setFileName(file_name) job.progress.connect(self._onProgress) job.finished.connect(self._onFinished) @@ -92,6 +93,10 @@ class RemovableDriveOutputDevice(OutputDevice): self.writeProgress.emit(self, progress) def _onFinished(self, job): + if self._stream: + self._stream.close() + self._stream = None + if hasattr(job, "_message"): job._message.hide() job._message = None