Computer Science Canada

Forking, threading, wha?

Author:  BuckMcCoy [ Sun May 31, 2009 11:24 pm ]
Post subject:  Forking, threading, wha?

Hi, basically all I'm trying to do in python is what you could do in Turing with the fork command. The reason being is there is some animation in my program that I don't want to be effected by a surrounding time.wait(). Unfortunately, although python does have os.fork() it doesn't work on Windows. Anyway, here's the animation as a function:
code:

def animate():
     dance = pygame.image.load("Images/Animations/dance.bmp").convert()
     Title = pygame.image.load("Images/Title.bmp").convert()
     ctr=0   
     while 1:
          ctr+=1
          if ctr==100000: #Animation
               dance=pygame.transform.flip(dance, True,False)
               screen.blit(dance, (391,330))
               screen.blit(tap, (118,385))         
               pygame.display.flip()
          elif ctr>=200000:
               screen.blit(Title,(118,385,25,19),(118,385,25,19))
               screen.blit(Title,(391,330,44,44),(391,330,44,44))
               pygame.display.flip()       
               ctr=0


What could I use to make this run parallel with my program without it just running and getting hung up in the while loop? (And how would I stop it when I'm through with it? Razz) Thanks!

Author:  DtY [ Tue Jun 02, 2009 7:17 am ]
Post subject:  RE:Forking, threading, wha?

this looks like what you want: http://docs.python.org/library/threading.html#thread-objects


: