Python 并行处理中的迭代

Python 并行处理中的迭代,python,parallel-processing,iteration,itertools,Python,Parallel Processing,Iteration,Itertools,我认为我很接近,但我无法找到迭代输入的正确方法。这是我的代码示例: from multiprocessing import Pool from functools import partial from itertools import product def f(n, x, y): return print("{} {} {}".format(n, x, y)) n = 3 c = [[1,2,3],[4,5,6]] d = [[7,8,9],[10,11,12]] if _

我认为我很接近,但我无法找到迭代输入的正确方法。这是我的代码示例:

from multiprocessing import Pool
from functools import partial
from itertools import product

def f(n, x, y):
    return print("{} {} {}".format(n, x, y))

n = 3

c = [[1,2,3],[4,5,6]]
d = [[7,8,9],[10,11,12]]


if __name__ == '__main__':
    p = Pool(3)
    func = partial(f, n)
    p.starmap(func, product(zip(c,d), repeat=2))
结果是:

3 ([1, 2, 3], [7, 8, 9]) ([1, 2, 3], [7, 8, 9])
3 ([1, 2, 3], [7, 8, 9]) ([4, 5, 6], [10, 11, 12])
3 ([4, 5, 6], [10, 11, 12]) ([1, 2, 3], [7, 8, 9])
3 ([4, 5, 6], [10, 11, 12]) ([4, 5, 6], [10, 11, 12])
但我想要的是

3 ([1, 2, 3], [7, 8, 9]) 
3 ([1, 2, 3], [10, 11, 12])
3 ([4, 5, 6], [7, 8, 9])
3 ([4, 5, 6], [10, 11, 12])

您的预期输出只是
c
d
的乘积,因此没有理由
zip
或重复

更改:

p.starmap(func, product(zip(c,d), repeat=2))
致:

演示:

p.starmap(func, product(c, d))