Event for multithread help advice

J

JoeSox

I have two threads going
class guiThread(threading.Thread)
class mainThread(threading.Thread)

Within the guiThread, I have an instance of class GUIFramework(Frame)
in this Tkinter instance I have a ListBox.

The second thread, mainThread, has an instance of a custom class the
will need to send out text or other objects to the gui.

What is the best or easiest way to send, let's say text, from
mainThread to the guiThread ListBox?

Should I use a custom Event class, pubsub, or Queue?

This is the way I have things right now (not in its entirety):
-----
start.py
import threading
import thread
import time
import GUIFramework
import myFoo
class guiThread(threading.Thread):
def __init__(self, threadID, name):
self.threadID = threadID
self.name = name
self.guiFrame = GUIFramework(master=None)
threading.Thread.__init__(self)
def run(self):
print "Starting " + self.name
self.guiFrame.mainloop()
print "Exiting " + self.name

class mainThread(threading.Thread):
def __init__(self, threadID, name):
self.threadID = threadID
self.name = name
self.myFoo = myFoo()
threading.Thread.__init__(self)
def run(self):
print "Starting " + self.name
self.myFoo.alive()
print "Exiting " + self.name

def start():
""" Start """
#Create new threads
threadgui = guiThread(1, "threadgui")
threadmain= carlThread(2, "threadmain")
#Start new Threads
threadgui.start()
threadmain.run()
while threadmain.isAlive():
if not threadgui.isAlive():
doExit = 1
pass
print "Exiting Main Thread"

if __name__ == '__main__':
start()
 
A

Aahz

I have two threads going
class guiThread(threading.Thread)
class mainThread(threading.Thread)

Within the guiThread, I have an instance of class GUIFramework(Frame)
in this Tkinter instance I have a ListBox.

The second thread, mainThread, has an instance of a custom class the
will need to send out text or other objects to the gui.

What is the best or easiest way to send, let's say text, from
mainThread to the guiThread ListBox?

Should I use a custom Event class, pubsub, or Queue?

Well, I'd recommend a Queue, but that's partly because I have an example
already made up:
http://www.pythoncraft.com/OSCON2001/FibThreaded.py
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top