#coding=utf-8
import threading
from time import ctime,sleep
def music(func):
for i in range(8):
print "I was listening to %s. %s" %(func,ctime())
sleep(2)
def move(func):
for i in range(4):
print "I was at the %s! %s" %(func,ctime())
sleep(3)
threads = []
t1 = threading.Thread(target=music,args=('music',))#方法 参数
threads.append(t1)
t2 = threading.Thread(target=move,args=('movie',))
threads.append(t2)
if __name__ == '__main__':
for t in threads:
t.setDaemon(True)
t.start()
t.join()
print "all over %s" %ctime()
python多线程demo
最新推荐文章于 2023-01-03 21:01:54 发布