Search code examples
pythondjangoshared-memoryweb-frameworks

What's the best way to get continuous data from another program in Django?


Here's the setup: On a single-board computer with a very rudimentary linux I'm running a Django app. This app is, when a button is pressed or as a response to the data described below, supposed to call either a function from a library written in C, or a compiled C program, to write data to system memory at a specified address, poke/peek like. (Python doesn't seem to be able to do that natively).
The Django app should also display data, continuously, which is being read from the memory from the same library / program.

My question now is how to even begin with setting up the scenario described above. Is this even possible with a web app? Is a Django or more fundamentally any web framework even the right approach here? I'm at a bit of a loss here, since I've spent quite a few hours now trying to figure out how to do this while not getting the most basic starting point...


Disclaimer: I'm pretty new to the entire web framework thing, and more importantly web development in general, so sorry if this is a bad question as in, I could have easily found information on this topic online, but I couldn't really find a good starting point on this.


Solution

  • I wanted to add a comment but not enough space... anyway

    You can write a native extension in C for Python that could do what you need, check this.

    Now for the fact of displaying data continuously this is kind of vague, if this C library is switching this hypothetical address, very often and very fast you have to update a browser client as fast as possible.

    I think websockets would do the trick but they are js related, so I think NodeJs would be a better candidate for the server side of your application instead of Django.

    If you want to stick to Django you can also expose an URL with the generated address value and have a webpage continuously (with a little Interval) checking that URL using a simple ajax call, kind of ugly and inefficient but would work.

    Anyway IMHO your best bet is for websockets because with them you have a fullduplex communication between client and server.

    Good Luck with your project.

    Info:

    Websockets in Django with socket.io

    Nodejs socket.io