关于tornado的raise gen.Retuen()

raise gen.Return(response.body)在python3.3以后作用相当于return, 在python3.3之前作用是返回一个异常值, 和返回一个value

python 3.3之后直接使用return

回调函数处理异步

from tornado.httpclient import AsyncHTTPClient

def asynchronous_fetch(url, callback):
    http_client = AsyncHTTPClient()
    def handle_response(response):
        callback(response.body)
    http_client.fetch(url, callback=handle_response)

协程处理异步

from tornado import gen

@gen.coroutine
def fetch_coroutine(url):
    http_client = AsyncHTTPClient()
    response = yield http_client.fetch(url)
    raise gen.Return(response.body)

原文地址:https://www.cnblogs.com/lph970417/p/11642139.html