线程池执行器需要关于调用函数或调用前一些步骤的建议 executor.submit

Threadpool executor Need Suggestion on call function or some steps before call executor.submit

我有一个类似下面的并行线程池执行

with concurrent.futures.ThreadPoolExecutor(max_workers=workers) as executor:
     # Start the load operations and mark each future with its URL
     print("starting parallel execution")

     future_to_conn = {executor.submit(connect, host, 22): host for host in arr}

现在我有了一些方法和功能

like def a, def b 我不需要在循环中调用它 like

for host in arr
       p=a(host)
       q=b(host)
       time=datetime.now()
       connect(host, 22,p,q,time )

但是我做不到

我试过了

 future_to_conn = {
    for host in arr :
         p=a(host)
         q=b(host)
         time=datetime.now()
         executor.submit(connect(host, 22,p,q,time))


     }

但是它失败了,没有工作任何帮助对我来说都是有益的

我通过以下操作得到了一个答案

with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
    future_to_conn ={} 
    p=a(host)
    q=b(host)
    time=datetime.now() 
    for host in arr:
       future_to_conn[executor.submit(connect, host, 22, p, q, time)] = host
       
    for future in concurrent.futures.as_completed(future_to_conn):
         data = future.result()
         print(data)