I've never tried using threading with pygtk, but I do have two suggestions:
1) Don't use threads. Figure out how to do it with callbacks if at all possible. But it seems that you've already thought of that. 2) Don't use gtk.main(). gtk.main() is an infinite loop. If you don't need to pick up button presses and the like, you can do quite nicely by calling gtk.main_iteration_do(), which will run gtk's main loop once. I've posted a usage example to http://gist.github.com/401433 . Happy programming! -Alan On Fri, May 14, 2010 at 11:48 AM, Neil Benn <[email protected]> wrote: > Hello, > > I have a very simple question which is stumping me. I want to start > up PyGTK and then do some interaction with my business layer to do the work > I need so that I can display the data on my PyGTK app. I'm setting up a > window and then calling gtk.main(). However when I do that everything else > freezes; I'm starting up an app and running something on a separate thread > in the background by gtk.main just stops running. I've recreated the > problem in a simple use case below which is: > > <code> > import pygtk > pygtk.require('2.0') > import gtk > import time > from threading import Thread > > class W(Thread): > def __init__(self): > Thread.__init__(self) > self.window = gtk.Window() > > def run(self): > self.window.show() > gtk.main() > > class A(Thread): > def __init__(self): > Thread.__init__(self) > self.count = 0 > > def run(self): > while True: > print 'a', self.count > self.count += 1 > > class B(Thread): > def __init__(self): > Thread.__init__(self) > self.count = 0 > > def run(self): > while True: > print 'b', self.count > self.count += 1 > > if __name__ == '__main__': > a = A() > b = B() > w = W() > a.start() > b.start() > time.sleep(2) > w.start() > while True: > time.sleep(0.1) > </code> > > This starts up as you would expect, printing a and b to the screen as the > threading time time slicing allows. However once the PyGTK window has opened > - these threads just freeze. I'm sure I cannot be the only person who deals > with this and it seems crazy to try and run everything on the GTK thread as > it would surely make the GUI unresponsive on operations which take a long > time? > > Note that I cannot trigger the app's business layer to start processing on > a button click as the app needs to interact with the business layer (a > camera capturing frames) from the word go and the application screen must be > very simple with no buttons to click at all (it is just used to report the > output from the camera after some frame processing). > > Thanks, in advance for your help. > > Cheers, > > Neil > > -- > -- > > Neil Benn Msc > Director > Ziath Ltd > Phone :+44 (0)7508 107942 > Website - http://www.ziath.com > > IMPORTANT NOTICE: This message, including any attached documents, is > intended only for the use of the individual or entity to which it is > addressed, and may contain information that is privileged, confidential and > exempt from disclosure under applicable law. If the reader of this message > is not the intended recipient, or the employee or agent responsible for > delivering the message to the intended recipient, you are hereby notified > that any dissemination, distribution or copying of this communication is > strictly prohibited. If you have received this communication in error, > please notify Ziath Ltd immediately by email at [email protected]. Thank you. > > _______________________________________________ > pygtk mailing list [email protected] > http://www.daa.com.au/mailman/listinfo/pygtk > Read the PyGTK FAQ: http://faq.pygtk.org/ > _______________________________________________ pygtk mailing list [email protected] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
