I’m trying to run a function with 2 arguments using concurrent.futures.ThreadPoolExecutor()
Function:
def test(var1, var2):
return var1 + var2
How do I pass x and y as the two arguments / values for this function?
x = 'text1'
y = 'text2'
process = concurrent.futures.ThreadPoolExecutor().submit(test, PASS_TWO_ARGUMENTS_HERE)
z = process.results()
I found various answers, but they all mentioned complex cases and solutions; can someone provide a simple 1-line solution for this without changing the function itself?
>Solution :
You can use lambda function for your purposes:
from concurrent.futures import ThreadPoolExecutor
def test(var1, var2):
return var1 + var2
params = ['text1', 'text2']
process = concurrent.futures.ThreadPoolExecutor().submit(lambda p: test(*p), params)