ServerWrapper.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import os
  2. import tornado.gen
  3. import tornado.httpclient
  4. import tornado.httpserver
  5. import tornado.ioloop
  6. import tornado.options
  7. import tornado.web
  8. from tornado.options import define, options
  9. from model.common.file_pid import PID
  10. from urls import urls
  11. from model.log import logger
  12. log = logger()
  13. iTime = 300
  14. define("port", default=8008, help="run on the given port", type=int)
  15. class HttpServerWrapper(tornado.web.Application):
  16. def __init__(self, port=80,debug=True):
  17. self.port = port
  18. handlers = urls
  19. settings = {
  20. "cookie_secret": "",
  21. "login_url": "",
  22. "autoreload": True,
  23. "debug": False,
  24. "allow_remote_access": True,
  25. "template_path": os.path.join(os.path.dirname(__file__), "templates"),
  26. "static_path": os.path.join(os.path.dirname(__file__), "templates")
  27. }
  28. super(HttpServerWrapper, self).__init__(handlers, **settings)
  29. def main():
  30. PID.write()
  31. tornado.options.parse_command_line()
  32. http_server = tornado.httpserver.HTTPServer(HttpServerWrapper())
  33. http_server.listen(options.port)
  34. log.info("server start, listening on port %s" % options.port)
  35. tornado.ioloop.IOLoop.current().start()
  36. if __name__ == '__main__':
  37. main()