쓰레드(Thread)란 무엇인가?

thread - threading모듈

스레드 함수 1개 쓰고, 여러 개 찍어내기

import RPi.GPIO as GPIO
import time
import threading

led_red=17
led_green=27
led_blue=23
green=(led_green,1.3)
blue=(led_blue,1.7)
flag_exit=False

def blink_led(led_pin,blink):
    while True:
        GPIO.output(led_pin,True)
        time.sleep(blink)
        GPIO.output(led_pin,False)
        time.sleep(blink)
        if flag_exit: break

GPIO.setmode(GPIO.BCM)
GPIO.setup(led_red,GPIO.OUT)
GPIO.setup(led_green,GPIO.OUT)
GPIO.setup(led_blue,GPIO.OUT)

tBLg=threading.Thread(target=blink_led,args=green)#args가 중요함
tBLb=threading.Thread(target=blink_led,args=blue)

tBLg.start()
tBLb.start()

try:
    while True:
        blink_led(led_red,0.7)

except KeyboardInterrupt:
    pass

flag_exit=True
tBLg.join()
tBLb.join()
GPIO.cleanup()