进程是资源分配的基本单位,线程是CPU调度的基本单位
import threading
import time
threading.currentThread().setDaemon(True)
time.sleep(1)
print('main thread end')
RuntimeError: cannot set daemon status of active thread
import threading
import time
import os
def func():
time.sleep(5)
print("child thread finish")
threading.Thread(target=func).start()
print("main thread exit")
import threading
import time
def func():
time.sleep(3)
print('child thread exit')
t = threading.Thread(target=func)
t.setDaemon(True)
t.start()
print('main thread exit')
import threading
import time
import os
def func():
time.sleep(3)
print('child thread exit')
t = threading.Thread(target=func)
t.start()
os._exit(-1)
print('main thread exit')