471,347 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,347 software developers and data experts.

Event for multithread help advice

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()

-----
I've tried a fews things but I really haven't had any luck.
--
Thanks, Joe
Oct 27 '07 #1
1 1160
In article <ma**************************************@python.o rg>,
JoeSox <jo****@gmail.comwrote:
>
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
--
Aahz (aa**@pythoncraft.com) <* http://www.pythoncraft.com/

"Typing is cheap. Thinking is expensive." --Roy Smith
Oct 30 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by haptiK | last post: by
reply views Thread by r_obert | last post: by
5 posts views Thread by Simon Middlemiss | last post: by
reply views Thread by Kevin Jiang | last post: by
5 posts views Thread by Ekempd | last post: by
6 posts views Thread by jmartin | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.