Python 3.x Python3多处理在使用zip函数时,并非所有iterable都会一直被处理

Python 3.x Python3多处理在使用zip函数时,并非所有iterable都会一直被处理,python-3.x,multiprocessing,Python 3.x,Multiprocessing,我有一个简单的函数 @click.command() @click.option('--concurrency', default=multiprocessing.cpu_count(), help='The maximum requests to make to the server') @click.option('--file', prompt='File Location: ', type=click.File(encoding="utf8"), help='

我有一个简单的函数

@click.command()
@click.option('--concurrency', default=multiprocessing.cpu_count(), help='The maximum requests to make to the server')
@click.option('--file', prompt='File Location: ', type=click.File(encoding="utf8"),
              help='The File to load')
    def try_pool(file, concurrency):
        pool = multiprocessing.Pool(concurrency)
        pool.map(print, zip(file, [1]*3000) )
        pool.close()

    def simple_print(file)
        for i in zip(file, [1]*3000):
            print(i)


    if __name__ == "__main__":
        load_service()
该文件仅包含2879个条目。 如果我使用simple_print函数,我会得到以下结果(经过多次尝试)

python3 Test.py input.txt | wc-l
2879
但是,如果我多次使用try_pool,有时会得到2879,有时会得到2519,有时会得到2430

我想知道多处理模块是怎么回事。我使用的python版本是Python3.4.3,刚刚找到了答案

显然,调用pool.close()不足以使池处理所有请求。它后面必须跟pool.join()才能等待池完成

def try_pool(file, concurrency):
    pool = multiprocessing.Pool(concurrency)
    pool.map(print, zip(file, [1]*3000) )
    pool.close()
    pool.join()

现在,我真的希望这两种方法结合在一起,这样就不会像我那样导致愚蠢的错误。

您如何调用
try\u pool
?不知道我如何调用try\u pool有什么关系。它由单击选项包装。