在Python中映射您的多处理函数时,是否有可能更改的可迭代项?

问题描述 投票:-1回答:1

我想实现类似于下面代码的功能。我假设的是data()仅执行一次,并将其传递给函数。我想发生的是,每次触发该函数时,都会执行data()函数(由于该池中的最大进程= 1)。这有可能实现吗?

from multiprocessing import Pool

def data():
    return [] // list of some data from sql or ...

pool = Pool(3)
pool.map(myfunction, data())

非常感谢

python multiprocessing pool
1个回答
0
投票

你的意思是这个吗?

pool.map(myfunction, lambda: data())
© www.soinside.com 2019 - 2024. All rights reserved.