Event for multithread help advice

Discussion in 'Python' started by JoeSox, Oct 27, 2007.

  1. JoeSox

    JoeSox Guest

    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
     
    JoeSox, Oct 27, 2007
    #1
    1. Advertising

  2. JoeSox

    Aahz Guest

    In article <>,
    JoeSox <> wrote:
    >
    >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 () <*> http://www.pythoncraft.com/

    "Typing is cheap. Thinking is expensive." --Roy Smith
     
    Aahz, Oct 30, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RWtlbXBk?=

    Need an advice with this (multithread)

    =?Utf-8?B?RWtlbXBk?=, Feb 1, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    460
    Steve C. Orr [MVP, MCSD]
    Feb 1, 2005
  2. steve
    Replies:
    1
    Views:
    3,870
    Larry Barowski
    Jun 15, 2004
  3. Dimitri Ognibene
    Replies:
    1
    Views:
    346
    Oliver Wong
    May 1, 2006
  4. Michael Shestero

    stream in multiprocess (multithread) apps

    Michael Shestero, Dec 19, 2003, in forum: C++
    Replies:
    4
    Views:
    558
    Michael Shestero
    Dec 19, 2003
  5. r_obert@REMOVE_THIS.hotmail.com

    Multithread or Multithread DLL?

    r_obert@REMOVE_THIS.hotmail.com, Nov 27, 2004, in forum: C++
    Replies:
    0
    Views:
    2,255
    r_obert@REMOVE_THIS.hotmail.com
    Nov 27, 2004
Loading...

Share This Page