gpt4 book ai didi

python - Tkinter 和线程 - 异常 : out of stack space (infinite loop? )

转载 作者:行者123 更新时间:2023-11-28 18:49:56 24 4
gpt4 key购买 nike

我们使用 Tkinter GUI 实现了分布式聊天。当我将系统更新到 Fedora18 时,我在调用 Tkinter 事件时遇到异常,几乎与描述的相同 here :

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib64/python2.7/threading.py", line 551, in bootstrap_inner self.run()
File "/usr/lib64/python2.7/threading.py", line 504, in run self.target(*self.__args, **self.__kwargs)
File "/hachat/peer.py", line 156, in startRecvLoop
self.processMessage(msg, addr)
File "/hachat/peer.py", line 222, in processMessage
self.gui.receive(msg)
File "/hachat/gui.py", line 74, in receive
self.textfenster.insert(END,msg.name+": "+msg.text+'\n')
File "/usr/lib64/python2.7/lib-tk/Tkinter.py", line 2986, in insert
self.tk.call((self._w, 'insert', index, chars) + args)
TclError: out of stack space (infinite loop?)

这是 gui 类的片段:

import Tkinter
import ScrolledText
import tkMessageBox
import tkSimpleDialog
import threading

class gui(object):

def __init__(self, parent):
self.root = Tkinter.Tk()
self.textfenster = ScrolledText.ScrolledText(self.fpopup,width=90,height=24,background='white')
self.textfenster.pack(fill=Tkinter.BOTH, expand=Tkinter.YES)

def run(self):
self.guiRunThread = threading.Thread(target=self.root.mainloop())
self.guiRunThread.daemon = True
self.guiRunThread.start()

def receive(self,msg):
self.textfenster.insert(Tkinter.END,msg.name+": "+msg.text+'\n')
self.textfenster.see(Tkinter.END)

异常只出现在我的系统上,原因似乎是 tk 没有编译支持线程。我必须摆脱这个异常(exception)——因为程序是分布式的,它需要在不同的系统上运行。所以我问如何摆脱这个异常以及获得支持线程的tk的提示。我使用的 Python 版本是 2.7.3,Tcl/Tk 版本是 8.5。 导入 Tkinter; Tkinter.Tk().tk.eval("puts $tcl_platform(threaded)") 也返回异常。

最佳答案

我解决了队列与 Tk 通信的问题。参见 Mutli-threading python with Tkinter举个例子!

关于python - Tkinter 和线程 - 异常 : out of stack space (infinite loop? ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14521319/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com