Home > Software design >  Threadpool executor Need Suggestion on call function or some steps before call executor.submit
Threadpool executor Need Suggestion on call function or some steps before call executor.submit

Time:05-10

I have a parallel threadpool execution like below

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}

Now I have some methods and functions

like def a, def b I need t call it in the loop like

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

But I am not able to achieve it

I tried

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


     }

But it got failed not working Any help would be good for me

CodePudding user response:

I got one answer by doing below

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)
  • Related