첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
import threading
import time

class TestThread(threading.Thread):
    def __init__(self, message):
        threading.Thread.__init__(self)
        self.message = message
        self.daemon  = True
        self.event   = threading.Event()

    def run(self):
        while True:
            if self.event.is_set():
                break;
            time.sleep(1)
            print(self.message)

threadList = []

for message in ["you", "need", "python"]:
    thread = TestThread(message)
    threadList.append(thread)
    thread.start()

for i in range(10):
    time.sleep(1)
    print(i)

for thread in threadList:
    thread.event.set()

time.sleep(1)

"""
python
need
you
0
1
python
you
need
2
need
python
you
you
3
python
need
python
you
need
4
need
you
5
python
you
need
6
python
need
7
you
python
8
need
you
python
9
need
you
python
"""
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요