python 池映射多个参数 - 列表和变量作为输入

python Pool map multiple arguments - list and variable as input

我想对一个函数进行多处理(见下文)

def func(c):
    time =  time
    list = [c, time]
    another_func(list)

我运行上面的函数如下:

p = multiprocess.Pool()
p.map(func, cust, chunksize=1)
p.close()
p.join()

cust 是一个字符串列表,如

cust = ['c1', 'c2', ...]

现在我的问题是可以将时间变量放入 p.map 中,例如

p.map(func, cust, time, chunksize=1) 

我在这里搜索了多个主题,但没有找到匹配的主题。

谢谢 help/hints!

你可以使用 starmap:

def func(c, time):
    my_list = [c, time]
    another_func(my_list)


p.starmap(func, [(c, time) for c in cust], chunksize=1) 

更好:

p.map(another_func, [[c, time] for c in cust], chunksize=1)