#coding=utf-8
import threading
from time import ctime,sleep
def music(func):
for i in range(2):
print("I was listening to music %s.%s" %(func,ctime()))
sleep(1)
def move(func):
for i in range(2):
print("I was at the movies %s.%s" %(func,ctime()))
sleep(5)
"""
创建了threads数组,创建线程t1,使用threading.Thread()方法,在这个方法
中调用music方法target=music,args方法对music进行传参。 把创建好的线程t1装到threads数组中。
"""
threads = []
t1=threading.Thread(target=music,args=(u'爱情买卖',))
threads.append(t1)
t2=threading.Thread(target=move,args=(u'阿凡达',))
threads.append(t2)
if __name__=='__main__':
for t in threads:
t.setDaemon(True)
t.start()
t.join()
print("all over %s"%ctime())
python-多线程基础练习1
最新推荐文章于 2023-03-21 20:41:42 发布