[英]Python Stack Overflow with tkinter and threading
我有關於python堆棧溢出的問題。 我正在使用Tkinter和其他4個線程使用python編寫應用程序。 但問題是工作一個小時后,我收到堆棧溢出錯誤,應用崩潰。 我的問題:
謝謝!
class App():
def __init__(self, master):
self.master = master
notebook=ttk.Notebook(master,width=800,height=480)
frame1=ttk.Frame(notebook,style='TNotebook')
frame2=ttk.Frame(notebook,style='TNotebook')
frame3=ttk.Frame(notebook,style='TNotebook')
frame4=ttk.Frame(notebook,style='TNotebook')
notebook.add(frame1,text='p1')
notebook.add(frame2,text='p2')
notebook.add(frame3,text='p3')
notebook.add(frame4,text='p4')
notebook.pack()
self.varopt34=StringVar(master)
self.varopt34.set(datashowgui[27].strip())
self.opt34=OptionMenu(frame3,self.varopt34,'0','1')
self.opt34.config(background="gray80",font="Harabara",width=1,height=1,highlightbackground="white",activebackground="gray80",fg="white")
self.opt34.place(x=370,y=220)
varopt1=StringVar(master)
varopt1.set(fglines[5])
opt1=OptionMenu(frame4,varopt1,id1,id2,id3,id4,id5,command=self.forganize1)
opt1.place(x=150,y=18)
opt1.config(background="gray80",font="Harabara",width=11,height=2,highlightbackground="white",activebackground="gray80",fg="white")
tkButtonSave=tk.Button(frame3,image=clockimage16,text="Save Settings and Reboot",compound=CENTER,command=self.savesettings,bg="white",highlightbackground="white",activebackground="white",fg="white",font=("Harabara",15),width=250,height=20)
tkButtonSave.place(x=500,y=320)
tkButtonReset=tk.Button(frame4,image=clockimage16,text="Reset Sensors and Reboot",compound=CENTER,command=self.resetsensors,bg="white",highlightbackground="white",activebackground="white",fg="white",font=("Harabara",15),width=250,height=20)
tkButtonReset.place(x=500,y=320)
tkButtonQuit=tk.Button(master,image=clockimage16,text="Quit",compound=CENTER,command=self.quitwindow,bg="white",highlightbackground="white",activebackground="white",fg="white",font=("Harabara",20),width=100,height=20)
tkButtonQuit.place(x=600,y=420)
self.update_reading()
def savesettings(self):
f=open("tempconfigreference.txt","r")
datasaveref=f.readlines()
f.close()
f=open("tempconfig.txt","w+")
f.writelines(datasaveref)
f.close()
def quitwindow(self):
self.master.destroy()
def resetsensors(self):
f=open("temps.txt","r")
lines=f.readlines()
f.close()
f=open("organizedtemps.txt","w+")
f.writelines(lines)
f.close()
def savesensors(self):
#print('savesensorsisrunning')
organizetemp.dosave()
#&self.after(100 , savesensors)
def update_reading(self):
now=datetime.now()
nowpersian=jalali.Gregorian(now.year,now.month,now.day).persian_tuple()
self.master.after(580 , self.update_reading)
self.master.after(850 , self.savesensors)
def display(threadName):
#print (threadName)
root = Tk()
app = App(root)
root.mainloop()
是的,當然,這是控制GUI的線程之一的示例代碼和摘要。 這是具有遞歸功能的線程(經過裁剪以使其易於閱讀):
def startcommunicate(thread_name):
def cpu_temp():
htot1=open("finaltemps.txt","r")
linesorganized=htot1.readlines()
htot1.close()
if linesorganized:
cpu_temp=linesorganized[0]
else:
cpu_temp=0
return cpu_temp
try:
run (host='169.254.176.82', port=80, quiet=True)
except:
time.sleep(5)
startcommunicate('Thread-1')
我發現了問題。 它被遞歸地稱為“ startcommunicate”函數。 但是我應該找到一種更好的方式來編寫提到的線程(也許使用while循環)。 准備獲得任何幫助! 謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.