Created
December 10, 2013 02:42
-
-
Save mayflaver/7884973 to your computer and use it in GitHub Desktop.
tornado coroutine return
This file contains hidden or 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 tornado.ioloop | |
import tornado.web | |
import tornado.gen | |
import tornado.httpclient | |
from tornado.platform.caresresolver import CaresResolver | |
import time | |
@tornado.gen.coroutine | |
def test(): | |
client = tornado.httpclient.AsyncHTTPClient() | |
response = yield client.fetch('http://www.baidu.com') | |
response = response.body | |
# do something with the response | |
raise tornado.gen.Return(response) | |
class MainHandler(tornado.web.RequestHandler): | |
@tornado.gen.coroutine | |
def get(self): | |
response = yield test() | |
self.write(response) | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
if __name__ == "__main__": | |
application.listen(8888) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment