Last active
December 4, 2018 12:56
-
-
Save arvidfm/11067131 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
Can you show how to use PeriodicCallback as well? Or should I just use asyncio.Task instead to do periodic work?