守护线程

守护线程:只要主线结束,那么子线程当即结束,无论子线程有没有运行完成。线程

import threading,timeget

def run():
  time.sleep(3)
  print('哈哈哈')thread

for i in range(50):
  t = threading.Thread(target=run)
  t.setDaemon(True) #把子线程设置成为守护线程 ---- 当主线程结束后,子线程也会当即结束,无论有没有运行完成
  t.start()import

print('Done,运行完成。')
# time.sleep(3)im

相关文章
相关标签/搜索