线程在raw_input()上停止

时间:2013-02-16 18:46:41

标签: python alarm raspberry-pi

我想出来试图解决这个问题,我是python的新手,我试图用覆盆子pi编写报警系统。

alarm1线程停止等待alarm2线程raw_input,我该如何解决?提前致谢。 alarm1线程应始终运行,我将使用RFID卡激活/停用

以下代码:

import time
from threading import Thread
from datetime import datetime
from espeak import espeak
import piface.pfio as pfio
import subprocess
armed=0
p=None
pfio.init()

def alarm1():
 global armed
 print "Thread running"
 #time.sleep(5)
 while True:        
    if armed==1:
        #while True:
            #time.sleep(1)
            print "Alarm active"
            t2=datetime.now().strftime("%c")
            if pfio.digital_read(1)==1:
                print "Alarm! Groventre door open %s"%t2
            continue
    else:
        print "inactive"
        time.sleep(1)
        continue


def alarm2():
 global armed
 x=0
 textarm='"10 sekunder"'
 cards=["0008239337","00012434326"]
 print "Starting up...Disarmed\n"
 while True:
 print "Waiting for card:\n"
 data=raw_input()
 if data in cards :
            print "Valid card!"
            if armed==0:
                #espeak.synth("Card ok, armed in ten seconds")
                #subprocess.call('espeak -s 110 -vsv ' +textarm, shell=True)
                time.sleep(5)
                armed=1
                time.sleep(2)
                print "Armed\n"                                  
                #continue
            if armed==1:
                armed=0
                time.sleep(2)
                print "Disarmed\n"

                #t.join()                    
                #continue


def main():
 #armed=0
 global armed
 t=Thread(target=alarm1)
 t.setDaemon(True)
 t.start()
 t2=Thread(target=alarm2)
 t2.start()



if __name__=='__main__':
 main()

0 个答案:

没有答案