我有一些創建惡魔線程的Python代碼。父線程幾乎立即結束,但守護線程繼續打印睡眠。當父線程退出時,Python守護進程線程不會退出
import threading
import time
def int_sleep():
for _ in range(1, 600):
time.sleep(1)
print("sleep")
def main():
thread = threading.Thread(target=int_sleep)
thread.daemon = True
thread.start()
time.sleep(2)
print("main thread end...")
thread = threading.Thread(target=main)
thread.start()
內容sys.version:
'3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)]'
打印:
sleep
main thread end...
sleep
sleep
sleep
爲什麼不Python的守護線程退出父線程退出時?
退房的thread.daemon設置.. http://stackoverflow.com/questions/4330111/python-thread -daemon-property –