Created
November 16, 2018 21:12
-
-
Save Integralist/0548b4c9189653854cf4f06d0469c86f to your computer and use it in GitHub Desktop.
[Python Tornado UVLoop] #python #tornado #uvloop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import tornado.httpserver | |
import tornado.ioloop | |
import tornado.platform.asyncio as tornado_asyncio | |
import tornado.web | |
import uvloop | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.finish('hello world') | |
def make_app(): | |
return tornado.web.Application([ | |
(r'/', MainHandler), | |
]) | |
if __name__ == '__main__': | |
# configuration for uvloop | |
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) | |
tornado_asyncio.AsyncIOMainLoop().install() # not needed for tornado 5.0+ | |
app = make_app() | |
# traditional tornado setup... | |
# | |
# app.listen(9000) | |
# tornado.ioloop.IOLoop.current().start() | |
server = tornado.httpserver.HTTPServer(app, xheaders=True) | |
server.listen(9000) | |
# configuration for uvloop | |
asyncio.get_event_loop().run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment