"Raspbian Python脚本内存超载"

2024-05-06 08:10:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我有python脚本,它将串行数据写入文本文件,类似于记录器。当我在大约12小时内在raspberry pi上运行它时,它会使raspberry的所有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()

Tags: textfromimporttkinterlineserialwindowpartial