【问题标题】:process large text file using python multiprocessing使用 python 多处理处理大型文本文件
【发布时间】:2016-09-02 18:07:57
【问题描述】:

http://www.ngcrawford.com/2012/03/29/python-multiprocessing-large-files/ 我想使用多处理创建一个大型文本文件的字典,我发现了这个。但是我对作者在这段代码中使用的参数有一些疑问:

p = multiprocessing.Pool(4)

Pool 的参数是什么?换句话说,“4”是什么意思?

for chunk in grouper(10, test_data):

“10”是什么意思

【问题讨论】:

  • 考虑将问题的标题更改为涵盖您实际要问的内容。

标签: python-multiprocessing pool


【解决方案1】:

Pool(4) 表示您启动了一个由四个工作进程组成的池。

grouper 的参数在该网页的函数定义中进行了说明:

def grouper(n, iterable, padvalue=None):
    """grouper(3, 'abcdefg', 'x') -->
    ('a','b','c'), ('d','e','f'), ('g','x','x')"""

    return izip_longest(*[iter(iterable)]*n, fillvalue=padvalue)

输出列表将由每个 n 元素的块组成。

【讨论】:

    猜你喜欢
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 2018-09-20
    • 2011-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-04
    相关资源
    最近更新 更多