Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing updates from Python server to a web interface

I've written an algorithm in python and a web interface around that. After you submit the form and start the algorithm, I'd like to push and update data on the page as it's running. How can I accomplish this?

like image 732
bkvaluemeal Avatar asked Jul 03 '15 03:07

bkvaluemeal


1 Answers

To have real-time or semi-real time communications between the web page the options are

  • Automatically refresh the page after certain seconds using meta refresh tag in HTML <head>

  • Fetch updated data with JavaScript and AJAX HTTP GET: https://api.jquery.com/jquery.get/

  • Use server-sent sent events: http://www.html5rocks.com/en/tutorials/eventsource/basics/

  • Use WebSockets: http://www.html5rocks.com/en/tutorials/websockets/basics/

All approaches, excluding the first one, require rudimentary JavaScript skills besides knowing server-side Python. The latter two approaches recommend advanced understanding of real-time communications. Thus, if you are not familiar with the web development I recommend picking the meta refresh tag.

On the server side you need to start a process or a thread which to handle the long running process, then have this process to write its progress to a database. When the web UI updates itself, it reads the latest results from the database and pushes/pulles them back to the browser.

like image 161
Mikko Ohtamaa Avatar answered Oct 14 '22 04:10

Mikko Ohtamaa