import threading import time # print(time.sleep(0)) # print(time.ctime()) def music(): print(‘开始听歌 %s‘ %time.ctime()) time.sleep(3) print(‘停止听歌 %s‘ %time.ctime()) def game(): print(‘开始游戏%s ‘%time.ctime()) time.sleep(5) print(‘结束游戏 %s‘ %time.ctime()) if __name__ == ‘__main__‘: t1=threading.Thread(target=music,args=())#创建线程 t1.setDaemon()#设置守护线程 t1.start() t2=threading.Thread(target=game,args=()) t2.start() t1.join() print(‘ending====================‘)
原文地址:https://www.cnblogs.com/chenxincx/p/10845754.html
时间: 2024-10-03 21:41:17