Running a continous while loop in python along with Flask app
Question: I am working on writing a code in raspberry pi using python where i want the
user to input the set temperature and fan mode via web page i'm using flask
for that and the values are returned successfully but i also want to run a
infinite while loop along with the flask app which will compare the set
temperature with the current temperature from a sensor.. how do i achieve this
without interrupting the flask app?

    
    
    from flask import Flask
    from flask import render_template
    from flask import request
    from flask import redirect
    import time
    temp = ""
    t = ""
    fan_High = 0
    fan_Med = 0
    fan_Low =0
    fanspeed = ""
    
    
    app = Flask(__name__)
    
    
    @app.route('/form', methods=['POST'])
    def aziz():
        global temp ,fanspeed
        fanspeedlocal = ''
        if request.form['settemp'] != "":
            temp = request.form['settemp']
            templocal = temp
        else:
            templocal = temp
    
    
        if request.form['speed'] == "null":
            fanspeedlocal = fanspeed
        else:
            if request.form['speed'] == "High":
                fan_Med = False
                fan_Low = False
                fan_High = True
                fanspeed = "High"
                fanspeedlocal = fanspeed
            elif request.form['speed'] == "Med":
                fan_High = False
                fan_Low = False
                fan_Med = True
                fanspeed = "Medium"
                fanspeedlocal = fanspeed
            elif request.form['speed'] == "Low":
                fan_High = False
                fan_Med = False
                fan_Low = True
                fanspeed = "Low"
                fanspeedlocal = fanspeed
        print 'Settemp = %s' %temp
        print 'fanspeed = %s' %fanspeed
        return render_template('Output.html',temp=templocal,currtemp=strct,time=t,fanspeed=fanspeedlocal
    
    
    
    
    @app.route('/')
    def start():
        global t , fanspeed
        t = time.strftime("%H:%M:%S")    
        return render_template('Start.html',temp=temp,currtemp=strct,time=t,fanspeed=fanspeed)
    
    
    
    
    if __name__ == '__main__':
        app.debug = False
        app.run(host = '192.168.1.101')
    
    
    var = 1
    while var == 1:
        inttemp = int(temp)
        if currtemp >= inttemp:
                #set GPIO to high
        else:
                #set GPIO to low
    
        if fanspeed == 'High':
                #set GPIO to high
        elif fanspeed == 'Med':
                #set GPIO to high
        elif fanspeed == 'LOW':
                #set GPIO to high
        time.sleep(10)
    


Answer: I think, you just input the while command inside the:

    
    
    @app.route('/')
    def start():
    

or in some place which you like

