Python is too fast !

Roger Binns rogerb at rogerbinns.com
Sat Feb 21 05:55:38 EST 2004


> So I've coded an option - which opens a temporary window with a
> Tkinter text widget in a frame and outputs the answers to the window
> as it finds them. The trouble is that the recursion is very processor
> intensive and it 'freezes' the window and it doesn't update. (I'm
> running on an AMD XP1700 with Win XP).

You have two choices as to how to solve this.  One is turn your
code into a generator.  The gui code then becomes something like:

    for word in genanagrams():
          <display the anagram>
          <possibly call Yield in gui toolkit>

Your other choice is to put your anagram generation into a background
thread, and have it send updates to the main (gui) thread.  I have long
since given up on TkInter and use wxPython instead.  In wxPython you
can use wx.PostEvent to send updates from worker threads to the
gui thread.

To send information from the main (gui) thread, use a Queue.Queue.
Call put() to add stuff in the main thread, and in the worker threads
call get() to get what they should do.  Generally you would use
some sort of message object.

Roger





More information about the Python-list mailing list