如何让pool.starmap支持无限序列多进程(例如无限流来)

时间:2017-10-26 06:21:21

标签: python multiprocess

我做了一个非常简单的例子,看看starmap是否可以同时调用add_func和iter_func同时产生新的参数,但不幸的是,它没有工作

from functools import partial
from itertools import repeat
from multiprocessing import Pool, freeze_support
import time
def add_func(a, b):
    print(a,b)
    return a + b

def iter_func():
    i = 0
    while True:
        print("yeild")
        yield i,i+1
        i+=1
        time.sleep(1)
def main():
    with Pool() as pool:
        L = pool.starmap(add_func, iter_func())
        print(L)


freeze_support()
main()

0 个答案:

没有答案