We implemented a distributed chat, which is using a Tkinter GUI. As I updated my system to Fedora18 Im getting exceptions when calling a Tkinter event, almost the same as described 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?)
Here is a snipped out of the gui-class:
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)
The Exception appears only on my system, the reason seems to be that tk was not compiled with support for threads. I have to get rid of this Exeption – as the program is distributed it needs to run on different systems. So Im asking for how to get rid of this exception as well as an hint to get tk for supporting threads.
Im using Python version is 2.7.3, Tcl/Tk version 8.5. import Tkinter; Tkinter.Tk().tk.eval("puts $tcl_platform(threaded)") is giving back a Exception as well.
I solved the problem with Queues to communicate with Tk. See Mutli-threading python with Tkinter for an example!