1 #!/usr/bin/python2 #Coding=utf-83 fromTimeImportCtime,sleep4 ImportThreading5 6 classMythead (Threading. Thread):7 def __init__(self,func,args,name="'):8Super (Mythead,self).__init__()9Self.name=nameTenSelf.func=func Oneself.args=args A defRun (self): -Self.func (*Self.args) - the - - defplayer (filename,time): - forIinchRange (2): + Print "starting playing:%s%s"%(Filename,ctime ()) - Sleep (time) + Ad={'1.mp3': 4,'2.mp4'75A'3.mp3': 7} atL=[] - forFilename,timeinchD.items (): - #t=threading. Thread (target=player,args= (filename,time,d)) -T=mythead (Player, (Filename,time), player.__name__) - - l.append (t) in - forIinchL: to I.start () + PrintThreading.currentthread ()#current main Thread object - PrintThreading.enumerate ()#all active threads in the current process the forIinchL: * I.join () $ Panax Notoginseng Print "End:", CTime ()
Python-thread wrapper class Create thread