多线程

启动60个线程项目源码

 1 def super_player(file,time):
 2     for i in range(2):
 3         cmd = 'cmd.exe /k java -jar disconf-spring-boot-web-1.0.0.jar'
 4         # yield os.system(cmd)
 5         os.system(cmd)
 6         print 'Start playing: %s! %s' %(file,ctime())
 7         sleep(time)
 8 
 9 
10 list = {'阿凡达.mp4':5,'我和你.mp3':4,'我和你.3':2,'1.mp3':1,'2.mp4':2,'6.mp3':6,'7.3':7,'8.mp3':1,'9.mp4':2,'10.mp3':6,'11.3':7,'12':7,'13.mp3':1,'14.mp4':2,'15.mp3':6,'16.3':7,'17':7,'18.mp3':1,'19.mp4':2,'20.mp3':6,'21.3':7,'22':7,'23.mp3':1,'24.mp4':2,'25.mp3':6,'26.3':7,'27':7,'28.mp3':1,'29.mp4':2,'30.mp3':6,'31.3':7,'32':7,'33.mp3':1,'34.mp4':2,'35.mp3':6,'36.3':7,'37':7,'38.mp3':1,'39.mp4':2,'40.mp3':6,'41.3':7,'42':7,'43.mp3':1,'44.mp4':2,'45.mp3':6,'46.3':7,'47':7,'48.mp3':1,'49.mp4':2,'50.mp3':6,'51.3':7,'52':7,'53.mp3':1,'54.mp4':2,'55.mp3':6,'56.3':7,'57':7,'58.mp3':1,'59.mp4':2,'60.mp3':3}
11 #,'41.3':7,'42':7,'43.mp3':1,'44.mp4':2,'45.mp3':6,'46.3':7,'47':7,'48.mp3':1,'49.mp4':2,'50.mp3':6
12 # '51.3':7,'52':7,'53.mp3':1,'54.mp4':2,'55.mp3':6,'56.3':7,'57':7,'58.mp3':1,'59.mp4':2,'60.mp3':6,'61.3':7,'62':7,'63.mp3':1,'64.mp4':2,'65.mp3':6,'66.3':7,'67':7,'68.mp3':1,'69.mp4':2,'70.mp3':6,'71.3':7
13 # list = {}
14 # for key,value in range(3),range(3):
15 #     list['key']=value
16 #     print list
17 # print list
18 
19 threads = []
20 files = range(len(list))
21 
22 #创建线程
23 for file,time in list.items():
24     t = threading.Thread(target=super_player,args=(file,time))
25     threads.append(t)
26 
27 if __name__ == '__main__':
28     #启动线程
29     for i in files:
30         threads[i].start()
31     for i in files:
32         threads[i].join()
33 
34     #主线程
35     print 'end:%s' %ctime()
原文地址:https://www.cnblogs.com/xiaoyaowuming/p/5630030.html