Background:
I have a C application running under Linux utilizing shared memory. I also have a debugger written in Python that can link to said shared memory and access individual variable values of global scope.
Question:
How can I develop a local browser-based application/page that, via my Python process, I can connect with in order to display near real-time variable values in a prettified form?
Usage:
I should be able to launch my background applications, then launch this server/client application in a browser, then be given an option to load a page with list of variables names (2-way communication), after which it simply should start displaying all the names with their values.
What I need:
Technical, process-flow solution, that utilizes solely Python if possible (understanding html/css/js/etc are necessary), and provides the ability to update the browser page’s list of values automatically at >= 20Hz.
Additional details:
- It needs to update the page between 20-60Hz, preferably in order (e.g. ‘time’ may be a value and want to update as 1.3 -> 1.4 -> 1.5…
- Only needs to work with Firefox
- Linux-only development, don’t care about Windows or Mac
- I don’t want to use a real GUI app like QT/WX/GTK
4
The concept of a local web app is a good and appropriate one. I have built several of these, and they work well. They have very fast update times, and let me work with Web tools rather than the declining breed of GUI toolkits.
I recommend a WebSocket-based connection between your Python code and your web page/client/app. This will give you near-real-time update speed and the ability to communicate bi-directionally between Python and a JavaScript-based front-end/app. You can use whatever JavaScript frameworks or widgets you like. There are some quite good graphing, plotting, and visualization frameworks for web apps these days–some better than what you typically see in GUIs, even.
There are an increasing number of ways to integrate WebSockets and Python. I prefer the Flask web app framework for its combination of simplicity and generality. You can run it natively (it has a built-in web server), atop Tornado, behind a real web server, etc. For a local app, you may want to review this simple demo which requires no extra middleware.
1
You might use an HTTP server library like libonion (or perhaps Wt), perhaps even in your C application, and use AJAX techniques (perhaps with Jquery) -and perhaps WebSocket- to periodically update the dynamic web page. FWIW, my MELT monitor is doing this.
Notice that web technology cannot guarantee any update frequency, in particular in the event of long latency (imagine the browser being in Australia, and your C application running in the middle of the USA with a bad internet connection between them). But if both the HTTP server program (e.g. your C application using libonion
) and the browser are near (on the same LAN) you probably would be able to get 20Hz updates.
In my view, you might not need any Python or PHP code (by adding HTTP server ability in your C application with libonion
). However, you need to become familiar with web technologies (HTML5, Javascript, DOM) and HTTP. For that w3schools -and other websites- is not perfect but has a lot of useful information.
If for whatever reason you still need to have a separate Python process, I’m sure you would be able to find Python HTTP server libraries.