Search code examples
pythonmultithreadingdaemontornado

Giving my Python application a web interface to monitor it, using Tornado


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?


Solution

  • Is it possible to use the threading package and run Tornado inside of its own thread?

    Edit:

    The threading module documentation at http://docs.python.org/library/threading.html has more details, but I am imagining something like this:

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

    Let me know if that works!