views:

71

answers:

3

I've got a Python application which is daemonized and running on a server 24/7. I'd like to be able to give an incredibly simple web interface so that I can monitor the changing values of a few variables within the program.

I'm using Tornado, and I'm up and running with the simple 'Hello, world' that you can find on the Tornado homepage. However, as soon as tornado.ioloop.IOLoop.instance().start() is called, it enters into the loop and doesn't return. My existing program is (essentially) an infinite loop as well, but I want to integrate the two.

So, my question is: how can I construct my program so that I can monitor variables inside my infinite loop by using Tornado to provide a web interface?

+1  A: 

I believe that the best (read: easiest) approach would be to have your daemon app write those particular variables you want to monitor out to a shared spaced that your tornado app can access. This could be a file, a socket, a database, or key-value store. Some ideas ideas that come to mind is to use your existing database (if there is one,) sqlite, or even memcached. Then, you would simply have your tornado application read those values from wherever you stored them.

You are correct in that once you run tornado.ioloop.IOLoop.instance().start() tornado's control flow never returns from that loop. From that point forward, your application's control will stay within the Application and RequestHandlers that you defined.

Charles Hooper
A: 

Another less elegant solution would be to utilize yaml to serialize the objects periodically from your main app, and have the web app read those in. You can even dump objects into yaml, so you could see the different states of those.

spowers