본문 바로가기
국비교육

Python 7일차

by Diligejy 2019. 5. 9.

1.

Daemon Thread에 대해서 

 

 

# -*- coding:utf-8 -*-
import threading

def Mythread():
    for i in range(100):
        print(i)
        
if __name__ == '__main__':
    t = threading.Thread(target = Mythread)
    t.setDaemon(True)
    t.start()

 

이렇게 작성한 뒤 쉘에서 실행하면 

다음과 같은 화면이 출력된다.

 

    t.setDaemon(True) # 부모스레드가 종료되면 자식스레드가 종료됨

 

2.

# -*- coding:utf-8 -*-
import threading


def Mythread():
    for i in range(100):
        print(i)


if __name__ == '__main__':
    t = threading.Thread(target=Mythread)
    t.setDaemon(True)
    t.start()
    if t.isAlive():
        print("daemon is alive")
        t.join(0.02)  # 스파크에서 스트리밍 처리 30초 단위 (60초) 간격 일괄처리
        

'국비교육' 카테고리의 다른 글

Python 10일차 - 프로젝트 팁  (0) 2019.05.14
Python 8일차  (0) 2019.05.10
Python 6일차  (0) 2019.05.08
Python 5일차  (0) 2019.05.07
Python 4일차  (0) 2019.05.03

댓글