【问题标题】:Tornado: pass more arguments to response callbackTornado:将更多参数传递给响应回调
【发布时间】:2017-04-29 21:13:10
【问题描述】:

我正在使用 tornado 发出一些异步 HTTP 请求。像这样:

from tornado.httpclient import AsyncHTTPClient

AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient", max_clients=10000)
HTTP_CLIENT = AsyncHTTPClient()
HTTP_CLIENT.fetch(request, handle_response)

def handle_response(response):
    """Handle response"""

我的问题是如何将另一个变量(参数)传递给handle_response?像这样(但不是这个):

HTTP_CLIENT.fetch(request, handle_response, some_variable)

def handle_response(response, some_variable):
    """Handle response"""

【问题讨论】:

    标签: python python-3.x http tornado


    【解决方案1】:

    使用“部分”:

    from functools import partial
    
    HTTP_CLIENT.fetch(request, partial(handle_response, some_variable))
    
    
    def handle_response(some_variable, response):
        """Handle response"""
    

    请注意,“some_variable”现在位于“response”之前。

    【讨论】:

      猜你喜欢
      • 2016-02-25
      • 2016-12-09
      • 2011-03-07
      • 1970-01-01
      • 2018-04-29
      • 1970-01-01
      相关资源
      最近更新 更多