如何访问ThreadPoolExecutor的返回值?

时间:2021-09-25 13:41:43

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.

如何访问从func返回的返回值?我试着通过考虑遗嘱执行人来弄清楚。map是一个包含值的列表,但对我来说并不适用。

1 个解决方案

#1


2  

May be you should try this

也许你应该试试这个

ablists = [alist, blist]

with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
    future_list= {executor.submit(func, a, b): i for i in ablists}

You can read more here about futures and also executors

你可以在这里读到更多关于期货和执行者的信息

#1


2  

May be you should try this

也许你应该试试这个

ablists = [alist, blist]

with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
    future_list= {executor.submit(func, a, b): i for i in ablists}

You can read more here about futures and also executors

你可以在这里读到更多关于期货和执行者的信息