import threading
import time
def music():
print(‘Listen music %s’% time.ctime())
time.sleep(3)
print(‘Stop the music %s’% time.ctime())
def game():
print(‘play games %s’% time.ctime())
time.sleep(6)
print(‘Stop the game %s’% time.ctime())
threads = []
t1 = threading.Thread(target=music)
t2 = threading.Thread(target=game)
threads.append(t1)
threads.append(t2)
if name == ‘main’:
# t2.setDaemon(True)#必须加start之前
# t1.setDaemon(True)
for t in threads:
t.setDaemon(True)
t.start()
print(‘ending…’, time.ctime())#主线程