Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 815
Sam Starling Avatar asked Oct 28 '10 12:10

Sam Starling


People also ask

What is tornado used for Python?

Tornado is a Python web framework and asynchronous network library, originally developed at FriendFreed. Tornado uses non-blocking network-io. Due to this, it can handle thousands of active server connections. It is a saviour for applications where long polling and a large number of active connections are maintained.

What is Tornado web application?

A Tornado web application generally consists of one or more RequestHandler subclasses, an Application object which routes incoming requests to handlers, and a main() function to start the server. A minimal “hello world” example looks something like this: import asyncio import tornado.web class MainHandler(tornado. web.


1 Answers

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!

like image 101
Brandon Rhodes Avatar answered Oct 16 '22 07:10

Brandon Rhodes