I have a simple bottle script that forwards button processes on a web page. Within the same script I was looking to have a continuous loop that among other tasks listened out for these button presses. I attempted to run the bottle script in a separate thread but it doesn't work as I expected.
Is there a better (or should I say correct) way to do this?
from bottle import get, post, request, run, redirect
import threading
@get('/button')
def button():
return '''
<form action="/button" method="post">
<input type="submit" value="Push" />
</form>
'''
@post('/button')
def action():
print "button pushed"
pushed = True
redirect("/button")
#run(host='localhost', port=8080)
threading.Thread(target=run, kwargs=dict(host='localhost', port=8080)).start()
def method():
pushed = False
print "started"
while 1:
# do other stuff
if pushed:
print "push recieved"
pushed = False
method()