Hi, I wonder if there is a way to give arguments to the callback through add_done_callback.
def print_result(future):
response = future.result()
print(response.url, response.status_code)
for url in list_urls:
future = session.get(url)
future.add_done_callback(print_result)
I would like to pass arguments, something like:
future.add_done_callback(lambda: print_result(str1, str2))
Is it possible ?
From what I read from the doc, it is not, but it would be very convenient:
add_done_callback(self, fn)
| Attaches a callable that will be called when the future finishes.
|
| Args:
| fn: A callable that will be called with this future as its only
| argument when the future completes or is cancelled. The callable
| will always be called by a thread in the same process in which
| it was added. If the future has already completed or been
| cancelled then the callable will be called immediately. These
| callables are called in the order that they were added.
duplicate of https://github.com/ross/requests-futures/issues/5, please take a look there
Ok thanks. I alos found a solution here actually:
https://docs.python.org/3/library/asyncio-task.html
future.add_done_callback(functools.partial(print_result, "papa", "maman"))
Just a few minutes after I opened the issue..
Most helpful comment
Ok thanks. I alos found a solution here actually:
https://docs.python.org/3/library/asyncio-task.html
Just a few minutes after I opened the issue..