多线程实例

 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()))
多线程代码

相关文章:

  • 2021-10-23
  • 2022-01-11
  • 2021-11-25
  • 2022-12-23
  • 2021-12-06
  • 2021-07-29
猜你喜欢
  • 2022-12-23
  • 2021-04-11
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
相关资源
相似解决方案