python 9 多線程
2023-03-04 10:35 作者:戎碼關(guān)山 | 我要投稿
多線程簡(jiǎn)單操作
import threading
def run(x,y):
? ?for i in range(y):
? ? ? ?print('輸出%s第%d次'%(x,i))
t1 = threading.Thread(target=run,args=('畫面',9))
t2 = threading.Thread(target=run,args=('聲音',9))
# t1.start()
# t2.start()
#isAlive
import time
def run():
? ?print('start')
? ?time.sleep(5)
? ?print('end')
t = threading.Thread(target=run())
t.start()
print(t.isAlive())
time.sleep(1)
print(t.isAlive)
#join
t1.start()
t1.join()
t2.start()#在t1結(jié)束之后才會(huì)執(zhí)行t2
#線程名
print(t.getName())
t.setName('newName')
print(t.getName())
標(biāo)簽: