-
-
Save xkou/ed130dd061c839d0ea79933f137df492 to your computer and use it in GitHub Desktop.
Running Tornado on asyncio's event loop, including 'yield from' support in request handlers
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.concurrent | |
import tornado.ioloop | |
import tornado.web | |
import tornado.platform.asyncio | |
import tornado.httpclient | |
class ReqHandler(tornado.web.RequestHandler): | |
async def get(self): | |
self.write("Hello world!\n") | |
print("Hej!") | |
await asyncio.sleep(2) | |
print("Hej igen!") | |
res = await tornado.httpclient.AsyncHTTPClient().fetch("http://google.com") | |
print(res) | |
self.write("Hello test\n") | |
app = tornado.web.Application([ | |
(r'/', ReqHandler) | |
]) | |
if __name__ == '__main__': | |
tornado.platform.asyncio.AsyncIOMainLoop().install() | |
app.listen(8080) | |
asyncio.get_event_loop().run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment