Reputation: 16436
I'm using tornado to make some async HTTP requests. as such:
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"""
My questions is how to pass another variable (argument) to handle_response
? Something like this (but NOT this):
HTTP_CLIENT.fetch(request, handle_response, some_variable)
def handle_response(response, some_variable):
"""Handle response"""
Upvotes: 1
Views: 455
Reputation: 24007
Use a "partial":
from functools import partial
HTTP_CLIENT.fetch(request, partial(handle_response, some_variable))
def handle_response(some_variable, response):
"""Handle response"""
Note that "some_variable" is now first, before "response".
Upvotes: 2