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.master
parent
3fe969e536
commit
16208aec18
|
@ -20,6 +20,7 @@ from threading import Thread
|
||||||
from select import error as SelectError
|
from select import error as SelectError
|
||||||
import time, getopt, sys
|
import time, getopt, sys
|
||||||
import platform, os
|
import platform, os
|
||||||
|
from collections import deque
|
||||||
from GCodeAnalyzer import GCodeAnalyzer
|
from GCodeAnalyzer import GCodeAnalyzer
|
||||||
|
|
||||||
def control_ttyhup(port, disable_hup):
|
def control_ttyhup(port, disable_hup):
|
||||||
|
@ -54,7 +55,7 @@ class printcore():
|
||||||
self.resendfrom = -1
|
self.resendfrom = -1
|
||||||
self.paused = False
|
self.paused = False
|
||||||
self.sentlines = {}
|
self.sentlines = {}
|
||||||
self.log = []
|
self.log = deque(maxlen = 10000)
|
||||||
self.sent = []
|
self.sent = []
|
||||||
self.tempcb = None #impl (wholeline)
|
self.tempcb = None #impl (wholeline)
|
||||||
self.recvcb = None #impl (wholeline)
|
self.recvcb = None #impl (wholeline)
|
||||||
|
@ -342,7 +343,7 @@ class printcore():
|
||||||
while self.printing and self.printer and self.online:
|
while self.printing and self.printer and self.online:
|
||||||
self._sendnext()
|
self._sendnext()
|
||||||
self.sentlines = {}
|
self.sentlines = {}
|
||||||
self.log = []
|
self.log.clear()
|
||||||
self.sent = []
|
self.sent = []
|
||||||
try:
|
try:
|
||||||
self.print_thread.join()
|
self.print_thread.join()
|
||||||
|
|
Loading…
Reference in New Issue