Ask for an asynchronous example of tornado

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)

asynchronous_fetch ("http://127.0.0.1:8000")

"

there is an example of asynchrony. Where callback is a parameter, it should be an external function call, but it also sets callback=handle_response, what is the function of callback here?

Mar.05,2021

fetch-> handle_response-> callback
fetch's callback, that is, handle_response deals with response
, while asynchronous_fetch 's callback handles response's body
and this layer is estimated to do some extra processing. The named call of the function in


python can be written as http_client.fetch (url, handle_response) or


can you format the code and give an address in the original text?

Menu