#coding=utf-8
#多线程:将onethreads.py单线程改为多线程并行
import threading #引入线程模块
from time import sleep,ctime
#创建音乐任务
def music(func):
for i in range(2):
print('I was listening to %s! %s'%(func,ctime()))
sleep(2)
#创建看电影任务
def movie(func):
for i in range(2):
print('I was at the %s! %s'%(func,ctime()))
sleep(3)
threads = []
#创建线程t1、t2,并添加到线程数组
t1 = threading.Thread(target=music,args=('first dance',))
threads.append(t1)
t2 = threading.Thread(target=movie,args=(u'都挺好',))
threads.append(t2)
if __name__ == "__main__":
#启动线程
for i in threads:
i.start()
#守护线程
for i in threads:
i.join()
print("All end:",ctime())