[Tutor] program hangs in while loop using wx.yield

Alex Hall mehgcap at gmail.com
Sun Nov 14 07:23:51 CET 2010


Hi all,
I had this working back in the summer, but have since had to
restructure some things in the code. Now, my program is hanging while
it waits for the human player to take his/her turn, and I am not sure
how to free it; as long as it hangs, the player cannot do anything, so
it continues to hang... You get the idea. Here is the loop:

  while not self.grid.turnOver:
   print("in while") #just a test to make sure I got this far
   wx.Yield()
   time.sleep(1)
  #end while

self.grid is a Grid object which, among other things, is a wx frame
with a sizer inside of it. This Grid class has many functions, and
some of them change the Grid's "turnOver" variable. Therefore, I loop
until I see that the user performed an action on the grid that sets
the Grid's turnOver to true, at which point the loop stops and the
other user (a computer in this case) can go. The problem is that this
loop makes the app hang, with Windows saying it is not responding. Of
course, the user can now not do anything at all, so I have to use
ctrl-c from the cmd window where I launched it to kill it. Does anyone
have a thought? Grid has no loops in it where the program could be
getting stuck and, besides, it hangs immediately, not even giving me
time to call any Grid function. Is this solvable, or should I just use
threads? I hate to launch every new turn in a separate thread as it
seems that this would quickly get out of hand, but if I have to I can
do it. TIA.


-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap


More information about the Tutor mailing list