线程的join方法
code
from threading import Thread import time def sayhi(name): time.sleep(2) print('%s say hello' % name) if __name__ == '__main__': t = Thread(target=sayhi, args=('nick',)) t.start() t.join() #主线程等待子线程结束 print('主线程') print(t.is_alive())
outputs
macname@MacdeMacBook-Pro py % python3 cccccc.py
nick say hello
主线程
False
macname@MacdeMacBook-Pro py %