我有python脚本,可以将串行数据写入文本文件,有点像记录器。当我在树莓派上运行它约12小时时,它会使树莓派的所有RAM过载,并且会挂断(放慢)主板的速度。最初,我认为这是全局变量重载内存,但不是,不是,然后我认为可能是将长字符串写入变量,也将其消除了,减少初始功能并不能解决内存重载问题。 大师可以建议出什么问题吗?
from tkinter import *
from tkinter.ttk import Combobox, Checkbutton, Radiobutton, Progressbar
from tkinter import scrolledtext, messagebox, ttk, filedialog, Menu, Tk,
Canvas, Frame, BOTH, NW, colorchooser
import serial, time, math
from functools import partial
import tkinter as tk
from guiLoop import guiLoop
import glob
ArduinoSerial = serial.Serial()
......
.......
........
@guiLoop
def list_ser():
while 1:
if ser_connect == 1:
try:
send_com('R_S')
except:
print('Serial port is close!')
yield 1
#Create window:
window = Tk()
#window.state('zoomed') #for windows
#window.attributes('-zoomed', True) #for linux
show_all = tk.BooleanVar()
show_all.set(True)
..........
...........
............
#------------------Tab7-------------------------------------------
tab7 = ttk.Frame(tab_control)
tab_control.add(tab7, text='LINE from FILE')
#scrolledtext demo:
txt3 = scrolledtext.ScrolledText(tab7, width=40, height=10)
txt3.insert(INSERT, '')
txt3.place(relx=0.01, rely=0.01, height=860, width=1900)
#btn_get2 = Button(tab7, text='READ LINE FROM FILE',
command=partial(read_line,'0','10','20')) # delete logs in log file
btn_get2 = Button(tab7, text='READ LINE FROM FILE',
command=partial(read_line,'20')) # delete logs in log file
btn_get2.place(relx=0.13, rely=0.91, height=70, width=200)
#-----------------------------------------------------------------
tab_control.pack(expand=1, fill='both')
set_conf()
#serial_ports()
#get_logs()
list_ser(window)
window.protocol("WM_DELETE_WINDOW", closeWindow)
window.mainloop()