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

标签 python multithreading exception tkinter tk-toolkit

我们使用 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/

相关文章:

python - 在python中,如何导入文件名以数字开头

python - mysql/python 连接器使用参数和字典在处理空值时死亡

vb.net - 点网 : Is there a way to do a Join statement on the UI Thread?

java - 当 throw new Error() 写在 try block 中时,为什么不执行 catch block 。它只进入最后。后面的代码也没有执行

exception - 与 aeson/attoparsec 进行管道,一旦源没有更多数据,如何无异常地干净退出

python - Tensorflow:如何设置对数尺度的学习率和一些 Tensorflow 问题

python - Python 类引用的命名约定是什么

ios - 使用后台线程在 UICollectionViewCell 上加载视频以创建无缝滚动

java - 并行化 for 循环并填充多个数据结构

java - 如何记录格式化消息、对象数组、异常?