python threading wont start in background
Question: this is my class for turn on , turn off , and blink LED in raspberry pi i want
stop thread blink in some time ... but thread wont run in background ...

> class LED:
>  
>  
>     _GPIOPORT=None
>     flagstop=0
>     flag=threading.Event()
>  
>  
>     def __init__(self,GPIONUM):
>         self._GPIOPORT=GPIONUM
>         GPIO.setmode(GPIO.BOARD)
>         GPIO.setwarnings(False)
>         GPIO.setup(self._GPIOPORT, GPIO.OUT)
>         self.flag.set()
>  
>  
>     def TurnOn(self):
>         self.flag.clear()
>         print 'Turn On ...'
>         GPIO.output(self._GPIOPORT,True)
>  
>     def TurnOff(self):
>         self.flag.clear()
>         print 'Turn Off ...'
>         GPIO.output(self._GPIOPORT,False)
>  
>     def Blink(self,delay,e):
>         print 'Thread Blink Create ...'
>         t1=threading.Thread(self.BlinkThread(delay,e))
>         t1.start()
>         print 'Thread Started'
>  
>     def BlinkThread(self,delaytime,event):
>         print 'BlinkTrehad Start ....'
>         while not event:
>             GPIO.output(self._GPIOPORT,False)
>             sleep(delaytime)
>             GPIO.output(self._GPIOPORT,True)
>             sleep(delaytime)
>  

and this is my module for use this class :

    
    
    import LED
    from time import sleep
    import threading
    
        if __name__ == '__main__':
            e=threading.Event()
            e.set()
            ledblue=LED.LED(11)
            ledblue.TurnOn()
            sleep(1)
            ledblue.Blink(1,e)
            ledblue.TurnOn()
    

never "Thread Started" print in consol and loop run in line


Answer: You are calling BlinkThread() in the Thread constructor instead of just
passing the function reference and arguments and letting the thread start the
function. Change it to:

    
    
    def Blink(self,delay,e):
        print 'Thread Blink Create ...'
        t1=threading.Thread(target=self.BlinkThread, args=(delay,e))
        t1.start()
        print 'Thread Started'
    

