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

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


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 threadingt = threading.Thread(target = tornado.ioloop.IOLoop.instance().start)t.start()

Let me know if that works!


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.


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.