import time import sqlite3 from ablib import Pin import threading from Queue import Queue Output1=Pin('W9','OUTPUT') Input1=Pin('W21','INPUT') q = Queue() class mainthread(threading.Thread): def run(self): while True: time.sleep(0.5) conn = sqlite3.connect('../database/database.db') cur = conn.cursor() cur.execute("SELECT * FROM input") output = cur.fetchone() q.put(output) class threadout1(threading.Thread): def run(self): Input1.set_edge("both",self.pressed) while True: time.sleep(0.01) def pressed(self): temp = q.get() if temp[6]: if Output1.digitalRead(): Output1.off() else: Output1.on() #q.queue.clear() thrmain = mainthread() thrmain.deamon = True thrmain.start() thr1 = threadout1() thr1.deamon = True thr1.start()