#coding=utf-8
import threading
from time import ctime,sleep
def music(func):
for i in range(2):
print "I was listening to %s. %s" %(func,ctime())
sleep(1)
def move(func):
for i in range(2):
print "I was at the %s! %s" %(func,ctime())
sleep(5)
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()
if __name__ == '__main__':
for t in threads:
t.start()
for t in threads:
t.join()
print "all over %s" %ctime()
转至:https://www.cnblogs.com/fnng/p/3670789.htmlhttps://www.cnblogs.com/fnng/p/3670789.html
来源:https://www.cnblogs.com/weizhideweilai/p/12121316.html