ioloop.py 993 B

123456789101112131415161718192021222324252627282930
  1. import tornado.websocket
  2. from tornado.web import StaticFileHandler
  3. from .session import AsyncBasedSession, get_session_implement
  4. from .platform import STATIC_PATH
  5. from .platform.tornado import webio_handler
  6. def start_ioloop(coro_func, port=8080, debug=True, tornado_app_args=None):
  7. """
  8. tornado app arg
  9. websocket_max_message_size
  10. ``websocket_ping_interval``, ``websocket_ping_timeout``, and
  11. ``websocket_max_message_size``.
  12. """
  13. handlers = [(r"/io", webio_handler(coro_func)),
  14. (r"/(.*)", StaticFileHandler, {"path": STATIC_PATH,
  15. 'default_filename': 'index.html'})]
  16. tornado_app_args = tornado_app_args or {}
  17. app = tornado.web.Application(handlers=handlers, debug=debug, **tornado_app_args)
  18. http_server = tornado.httpserver.HTTPServer(app)
  19. http_server.listen(port)
  20. print('Open http://localhost:%s/ in Web browser' % port)
  21. tornado.ioloop.IOLoop.instance().start()