If you want to execute two while true loops at the same time, you can use multithreaded threading to implement them.
Full code
#CODING=GBK fromTimeImportSleep, CTimeImportThreadingdefMuisc (func): whileTrue:Print 'Start Playing:%s!%s'%(Func,ctime ()) Sleep (2) defMove (func): whileTrue:Print 'Start Playing:%s!%s'%(Func,ctime ()) Sleep (5)defplayer (name): R= Name.split ('.') [1] ifr = ='mp3': Muisc (name)Else: ifr = ='mp4': Move (name)Else: Print 'error:the format is not recognized!'List= ['love business. mp3','Avatar mp4.']threads=[]files=Range (len (list))#Creating Threads forIinchFiles:t= Threading. Thread (target=player,args=(List[i],)) Threads.append (t)if __name__=='__main__': #Start Thread forIinchFiles:threads[i].start () forIinchFiles:threads[i].join ()#Main Thread Print 'end:%s'%ctime ()
Effect:
Reference: http://www.cnblogs.com/fnng/p/3691053.html
Python Multi-threaded implementation performs two while loops at a time