From 16208aec187b4f20e4b80db99a67eb4678107af8 Mon Sep 17 00:00:00 2001 From: Guillaume Seguin Date: Sat, 18 May 2013 23:30:13 +0200 Subject: [PATCH] Use a fixed-size deque for storing the log deque is much better fitted than a simple Python list Indeed, a standard Python list is stored as an array, and has to be reallocated all the time, while a deque has very fast operation on both ends, and the fixed size mode will automatically drop first element when pushing to a full deque. Also it was crazy to store the whole log. Storing 10000 log lines seems decent and shouldn't take way too much space (less than 512KB based on a quick estimation). This might fix #292 and #353. --- printcore.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/printcore.py b/printcore.py index 5902d01..cabd9dc 100755 --- a/printcore.py +++ b/printcore.py @@ -20,6 +20,7 @@ from threading import Thread from select import error as SelectError import time, getopt, sys import platform, os +from collections import deque from GCodeAnalyzer import GCodeAnalyzer def control_ttyhup(port, disable_hup): @@ -54,7 +55,7 @@ class printcore(): self.resendfrom = -1 self.paused = False self.sentlines = {} - self.log = [] + self.log = deque(maxlen = 10000) self.sent = [] self.tempcb = None #impl (wholeline) self.recvcb = None #impl (wholeline) @@ -342,7 +343,7 @@ class printcore(): while self.printing and self.printer and self.online: self._sendnext() self.sentlines = {} - self.log = [] + self.log.clear() self.sent = [] try: self.print_thread.join()