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