Ok, I really hated to resort to threading, but it seems like I have no other choice. I am writing a client script for the "instant message" server I just finished writing. Sadly, I am having a slight problem with threading. What I would like to do is have two threads running simultaneously: thread one would control the main loop of the GUI, thread two would receive messages sent from the server. Yet, I am having trouble with this.
My code (Note, this is just the part that the threading concerns):
import threading class RecvData(threading.Thread): def __init__(self, client): print "RecvData thread started." while True: client.recvdata() class GUILoop(threading.Thread): def __init__(self, myapp): print "GUILoop thread started." myapp.mainloop() # Client Setup client = ChatClient() s = client.connect(host, port) # GUI Setup master = Tk() myapp = MyGUI() client.msgbox = myapp.setup(master, Tkinter, client) # Threads RecvData(client).start() GUILoop(myapp).start()
Now, when I run this code, only the first thread executes. So what am I doing wrong and how can I fix this to make both threads run at the same time?
Thanks very much in advance.