악마 스레드를 만드는 파이썬 코드가 있습니다. 상위 스레드는 거의 즉시 종료되지만 데몬 스레드는 인쇄를 계속 유지합니다.상위 스레드가 종료 될 때 파이썬 데몬 스레드가 종료되지 않습니다.
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
이유는 무엇입니까하지 파이썬 데몬 스레드 종료 부모 스레드가 종료?
체크 아웃 thread.daemon 설정 파이썬 테스트 .. http://stackoverflow.com/questions/4330111/python-thread -daemon-property –