Home >Backend Development >Python Tutorial >How to pass single parameter and multiple parameters to python thread pool ThreadPoolExecutor
from concurrent.futures import ThreadPoolExecutor,as_completed def test(a): print(a) qq = {"a":"1","b":"2","c":"3"} with ThreadPoolExecutor() as pool: for j ,k in qq.items(): res = pool.submit(test,j) kk = res.result()
This line of code needs to be disassembled and viewed
The first is the anonymous function: lambda cxp:test(*cxp) This is the first stepThis means: pass the cxp parameter to test
The second step is submit(lambda cxp:test(cxp),(j,k))sumbit method requires passing two parameters, the first one is function, the second one is the parameter of this function
The anonymous function just now is the first parameter, and then (j,k) is the second parameter. This parameter is to be passed to the function, so (j,k ) gives cxp
python thread pool to pass in multiple parameters ThreadPoolExecutor.submit multi-parameter support
from concurrent.futures import ThreadPoolExecutor,as_completed def test(a,b): print(a,b) qq = {"a":"1","b":"2","c":"3"} with ThreadPoolExecutor() as pool: for j ,k in qq.items(): res = pool.submit(lambda cxp:test(*cxp),(j ,k)) last= res.result())
The above is the detailed content of How to pass single parameter and multiple parameters to python thread pool ThreadPoolExecutor. For more information, please follow other related articles on the PHP Chinese website!