I've just begun learning concurrent programming in Python.
I created a function which takes one positional argument and then **kwargs.
Code:
def download_from_api(api_client_method, **kwargs):
try:
response = api_client_method(**kwargs)
return response
except api.exceptions.APIException as e:
print(f'{kwargs}: {api_client_method.__name__} - {e})
I'd like to pass this function to concurrent.futures.ThreadPoolExecutor().map()
object.
Below is the code i used for trying, passing everything as positional args
, but it didnt work:
these_should_be_passed_as_keyword_args = ['A', 'B']
n = len(these_should_be_passed_as_keyword_args)
functions = [api_client.relevant_method] * n
with concurrent.futures.ThreadPoolExecutor() as executor:
results = executor.map(download_from_api, functions, these_should_be_passed_as_keyword_args)
Any help is really appreciated.
Thank you!