How do I access the return values of ThreadPoolExecutor?

10,429

I don't know where your alist and blist variables are coming from, but you could do something like this.

def func(a,b):
    return (func2(a),func3(3))

def paralel_func(alist, blist):
    processes = []
    with ThreadPoolExecutor(max_workers=None) as executor:
        processes.append(executor.map(func, alist, blist))

        for _ in concurrent.futures.as_completed(processes):
            print('Result: ', _.result())
Share:
10,429
zython
Author by

zython

BSc Computer Science Student from 2015-2018 (hopefully) hoping learn some stuff and pursue a carrer in CS

Updated on June 05, 2022

Comments

  • zython
    zython almost 2 years

    Say I have the following code:

    def func(a,b):
        return (func2(a),func3(3))
    
    def paralel_func(alist,blist)
        with ThreadPoolExecutor(max_workers=None) as executor:
            executor.map(func,alist,blist)
    

    How do I access the return values that were returned from func ? I tried to figure it out myself by thinking that executor.map is a list that holds the values but that didnt work for me.

  • zython
    zython about 6 years
    wouldnt I have to loop over alist and blist to submit the futures ?
  • joe hoeller
    joe hoeller about 2 years
    Incomplete answers that do not show full scope are insuffcient. Where is number, prime and PRIMES defined at?