I'm making a flask application, and when the user presses a button I want for a thread to pause until the button is pressed again, and i'm planning to do this with a flag being set off. The thread can read the initial value of the flag, but when the user presses the button and the value is changed, the value remains false in the thread. It can read it successfully, but it just can't change it. I've tried making it global but it still has no effect. Here is the source -
web = False
@app.route("/")
def bg_func():
print('Thread test')
while True:
if web == False :
if Facial_Check.run() == True:
face_detected = True
t = Thread(target=bg_func)
t.start()
@app.route("/<changePin>/<action>")
def action(changePin, action):
changePin = int(changePin)
deviceName = pins[changePin]['name']
global web
if action == "on":
GPIO.output(changePin, GPIO.HIGH)
time.sleep(1)
GPIO.output(changePin, GPIO.LOW)
web = True
current_status = True
message = "Turned computer on."
if action == "off":
GPIO.output(changePin, GPIO.HIGH)
time.sleep(1)
GPIO.output(changePin, GPIO.LOW)
web = False
current_status = False
face_detected = False
message = "Turned computer off."
for pin in pins:
pins[pin]['state'] = GPIO.input(pin)
return render_template('index.html', Status=current_status)