标签:
先把可运行代码列出来, 注释和说明后续补充.
# -.- coding:utf-8 -.- # __author__ = ‘zt‘ import tornado.ioloop from tornado.concurrent import Future from tornado.httpclient import AsyncHTTPClient def async_fetch_future(url): http_client = AsyncHTTPClient() my_future = Future() fetch_future = http_client.fetch(url) fetch_future.add_done_callback(lambda f: my_future.set_result(f.result())) return my_future def main(): return async_fetch_future(‘http://www.qq.com‘).running() if __name__ == ‘__main__‘: response = tornado.ioloop.IOLoop.instance().run_sync(main) print response.body
参考: <http://www.tornadoweb.org/en/stable/guide/async.html#examples>
标签:
原文地址:http://my.oschina.net/u/2452965/blog/515165