import logging
import tornado.httpserver
import tornado.ioloop
import tornado.web
from tornado.options import define, options
define("port", default=8083, help="Run server on a specific port", type=int)
class MainHandler(tornado.web.RequestHandler):
def get(self):
logging.info("**Request to MainHandler!")
self.write("Hello to the Tornado world!")
settings = {
"debug": True,
}
application = tornado.web.Application([
(r"/", MainHandler),
], **settings)
if __name__ == "__main__":
http_server = tornado.httpserver.HTTPServer(application)
'''
Get the option(s) from the startup command line if ever.
In this tutorial, we define own "port" option to change the
port via the command line, and then we can run multiple tornado
processes at different ports.
'''
tornado.options.parse_command_line()
# This line should be after the parse_command_line()
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()