Background
I have a large number of fields that will be updating real time from an external process. I would like to update the Flask hosted pages periodic
No. Well, as least there's nothing in side of Flask that would make this easier than other solutions. SO has some decent material on implementing comet servers in Python.
As you mentioned, there you can use JavaScript to poll the server for new data. This can be difficult for your server to manage though if you have many users. Opening concurrent TCP connections is fairly expensive. It also means that your UI may appear slightly jerky, because things will be updating every second or so, rather than when new data hits the server.
With that in mind, Flask is excellent for this second choice because it is so easy to attach response functions to individual URLs. The main thing to note is you should functions which block heavily on I/O. Long-running functions will seize the whole application.
Let's say you have two temperature gauges & you're using jQuery.
@app.route('/gauge/')
def gauge_temp(gauge_id):
temp = temp_from_db(gauge_id) #implement this yourself
return dict(temp=temp, gauge_id=gauge_id)
In a JavaScript file, you could have some function that updates a DOM element every minute with the current temperature. This code should give you some idea of something you can build into an actual implementation:
function updateTemp(gauge_id, selector) {
$.getJSON('/gauge/' + gauge_id, function(data){
$(selector).text = response.temp;
})
}
setInterval('updateTemp(1, "#gauge-1")', 1000 * 60);
setInterval('updateTemp(2, "#gauge-2")', 1000 * 60);