pygtk, threads and the Game of Life

Padraig Brady Padraig at Linux.ie
Fri Dec 6 08:41:41 EST 2002


Simon Burton wrote:
> On Thu, 05 Dec 2002 16:00:59 +0000, Rajarshi Guha wrote:
> 
> 
>>HI,
>>  I'm new to threads and am trying to program a Game Of Life with PyGTK
>>and threads. The structure of my program is as follows:
>>
>>class GUIThread(Thread):
>>  
>>  def __init__(self):
>>   Thread.__init__(self)
>>  
>>  def run(self):
>>   # Create GUI
>>   gtk.mainloop()
>>
>>if __name__ == '__main__':
>>  g = GUIThread()
>>  g.run() 
>>  for i in range(0,1000): print i
>>
>>Now, I expected that the program would draw a window with a grid and
>>randomly fill in boxes and also print out the numbers from 1 to 1000 in
>>the console window. However, only the GUI shows and the numbers dont get
>>printed.

Sorry if this is answered already (my newsfeed is all over the place).
You don't need to g.run() explicitly (I'm assuming that
Thread.__init(self) calls thread.start_new(self.run)).

The reason no error is generated is that you can nest calls
to gtk.mainloop() (which is useful for modal dialogs etc.).

Pádraig.




More information about the Python-list mailing list