标签:
# -*- coding: cp936 -*- #python 27 #xiaodeng #http://www.cnblogs.com/fnng/p/3489321.html #创建多线程类 import threading from time import sleep,ctime class MyThread(threading.Thread):#threading.Thread ‘创建MyThread类,用于继承threading.Thread类.‘ def __init__(self,func,args,name=‘‘): ‘使用类的初始化方法对func、args、name等参数进行初始化.‘ threading.Thread.__init__(self) self.func=func self.args=args self.name=name def run(self): apply(self.func,self.args) def super_play(file,time): for i in range(2): print ‘Start playing:%s.%s‘%(file,ctime()) sleep(time) dict={u‘爱情买卖.mp3‘:3,u‘大秦帝国.mp4‘:5} #创建线程 threads=[] files=range(len(dict)) for k,v in dict.items(): print super_play.__name__#super_play #MyThread(super_play,(k,v),super_play.__name__) t=MyThread(super_play,(k,v),super_play.__name__) threads.append(t) if __name__==‘__main__‘: #启动线程 for i in files: threads[i].start() for i in files: threads[i].join() #主线程 print ‘End:%s‘%ctime()
标签:
原文地址:http://www.cnblogs.com/dengyg200891/p/4940995.html