报错信息
TypeError: test() argument after * must be an iterable, not int
代码
def test(i:int):
return i
t1 = time.time()
_gen = generator(100)
p = multiprocessing.Pool(10)
for i in _gen:
res_all = p.apply_async(test, args=(i)).get()
p.close()
p.join()
t2 = time.time()
print(f'apply_async cost time {(t2 - t1) / 60:.2f} min')
原因分析
args传入的参数需要是一个元组
args=(i,) #元祖