多线程实例
1 import threading 2 import time 3 4 5 def eat(): 6 eatTime = time.time() 7 for i in range(30): 8 print('count = {}'.format(count)) 9 time.sleep(1) 10 print 'eat something in {}'.format(eatTime) 11 return eatTime 12 13 def playGame(): 14 playTime = time.time() 15 16 for i in range(30): 17 global count 18 count += 1 19 time.sleep(1) 20 print 'play Game in {}'.format(playTime) 21 return playTime 22 count = 0 23 theadEat = threading.Thread(target=eat) 24 theatPlay = threading.Thread(target=playGame) 25 theadEat.start() 26 theatPlay.start() 27 eatT = theadEat.join() 28 playT = theatPlay.join() 29 30 # eatT = eat() 31 # playT = playGame() 32 33 print("over in {}!".format(time.time()))