I have an app where I'm monitoring the state of a switch while presenting a url for a user to activate another switch:
door="closed"
def switch():
global door
#handle GPIO SETUP
button_state = GPIO.input(#pin)
if button_state == True:
if door=="closed":
door="open"
if button_state == False:
door="closed"
def door_loop():
while True:
switch()
#printing door here returns either open or closed
time.sleep(1);
@app.route("/click", methods=['GET','POST'])
def clicky():
command = request.data
if command:
#turn other switch on
return json.dumps({'is_open':door})
if __name__ == '__main__':
p = Process(target=door_loop)
p.start()
app.run(
host="0.0.0.0",
port=int("5000"),
debug=True
)
p.join()
If I print out door
after the function call to switch()
I get the expected output when the door opens or closes (when I push the switch, I see "open" when I let it go, I see "closed"). But when I visit http://myapp.com/click I get {'is_open':'closed'}
no matter what the state of the switch is. Is there something that prevents flask from inheriting the modified global variable from the other process?