I'm trying to long poll my sql database, and when a change occurs do some other stuff. in the request lastRequestTime is a number which is compared to the number in the field last by changing the number on either database or request it works, but I'm expecting inside the while True block to keep checking the dB. It seems it reads it once only.
(eventual timeout I can handle)
my code is
#!/usr/bin/python2.7 from flask import Flask from flask import request from flask import jsonify, make_response from flask_mysqldb import MySQL import time app = Flask(__name__) app.config['MYSQL_HOST'] = 'jamesdavies000.mysql.pythonanywhere-services.com' app.config['MYSQL_USER'] = 'jamesdavies000' app.config['MYSQL_PASSWORD'] = 'myPassword!!' app.config['MYSQL_DB'] = 'jamesdavies000$default' app.config['MYSQL_CURSORCLASS'] = 'DictCursor' app.config['updated'] = False mysql = MySQL(app) @app.route("/poll", methods =['GET', 'POST']) def poll(): # request this and wait for response indicating change clientUpdateTime = request.args.get('lastRequestTime') cursor = mysql.connection.cursor() mySQLCommand = 'select Last from homeAutoPollCheck' while True: # poll sql for changes cursor.execute(mySQLCommand) retVal = cursor.fetchall() valueDb = str(retVal['Last']) if valueDb > clientUpdateTime: return valueDb, 201 time.sleep(1)