Providing my Python application a web interface to monitor it using Tornado

I have a Python application that is unmounted and runs on a 24/7 server. I would like to have an incredibly simple web interface so that I can control the change in the values ​​of several variables within the program.

I use Tornado and I work with a simple "Hello, world", which you can find on the Tornado homepage . However, as soon as tornado.ioloop.IOLoop.instance().start() is called, it enters the loop and does not return. My existing program (essentially) is also an infinite loop, but I want to integrate the two.

So my question is: how can I create my program so that I can control the variables inside my infinite loop using Tornado to provide a web interface?

+6
python multithreading tornado daemon
source share
4 answers

Can I use the threading package and run Tornado inside my own thread?

Edit:

The threading module documentation at http://docs.python.org/library/threading.html contains more detailed information, but I imagine something like this:

 import threading t = threading.Thread(target = tornado.ioloop.IOLoop.instance().start) t.start() 

Let me know if this works!

+4
source share

I believe that the best (simplest and most straightforward) approach would be for your daemon application to write down the specific variables that you want to keep track of at separate intervals that your tornado application can access. It can be a file, socket, database or keystore. Some ideas that come to mind are to use your existing sqlite or even memcached database (if you have one). Then you just ask the tornado app to read these values ​​from where you saved them.

You are correct that after starting tornado.ioloop.IOLoop.instance().start() , the tornado control flow never returns from this cycle. From this point of view, the management of your application will remain within the applications and RequestHandlers you define.

+2
source share

Another less elegant solution would be to use yaml to periodically serialize objects from your main application, and the web application should read them. You can even dump objects in yaml so you can see the different states of these.

0
source share

You can try http://www.zeromq.org/ as a means of communication between two processes / threads.

0
source share

All Articles