例如我有这样的代码
import itertools
from multiprocessing.dummy import Pool as ThreadPool
#combinations is from itertools which makes combinations from 3 elements of array
def build_func(i):
print(i)
operators=[1,2,3,4,5]
size=3
pool = ThreadPool(5)
pool.map(build_func, itertools.combinations(operators,size))
pool.close()
pool.join()
我想从生成器结果中创建线程,但是它确实很慢并且不能正常工作。 如果我只是使用
for i in itertools.combinations(operators,size):
build_func(i)
它工作更快,因此线程使用不正确。有没有办法使线程有用?