執行緒基本
阿新 • • 發佈:2018-11-21
from threading import Thread import threading import time def say(name): time.sleep(5) print('%s say hello'%name) if __name__=='__main__': t=Thread(target=say,args=('wes',)) t.start() print('zhu') print(t.is_alive()) print(t.getName()) print(threading.current_thread()) #主執行緒 print(threading.enumerate()) #返回主執行緒在內的所有正在執行的執行緒 print(threading.active_count()) #返回正在執行的執行緒的數量 t.join() #等待子執行緒 print('finish')
zhu True Thread-1 <_MainThread(MainThread, started 5416)> [<_MainThread(MainThread, started 5416)>, <Thread(Thread-1, started 5276)>]2 wes say hello finish