ioloop.py 1.0 KB

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