python2 mutilprocessing池图功能中的参数块大小的含义是什么?

发布于 2025-01-27 13:27:53 字数 1007 浏览 2 评论 0原文

在Python2中,MutilProcessing Pool函数映射,我设置了param'Chunksize = 2',但它不起作用。我把那是什么意思?代码如下:

from multiprocessing import Pool

import time
import os

work = [1,2,3,4,5,6]


def work_log(work_data):
    print "{} receive data: {}".format(os.getpid(), work_data)


def pool_handler():
    p = Pool(2)
    p.map(work_log, work,chunksize=2)


if __name__ == '__main__':
    pool_handler()


我收到RES如下:

25883接收数据:1

25884接收数据:3

25884接收数据:4

25883接收数据:2

25884接收数据:5

25884接收数据:6

Res应该是:[1,2 ],[3,4],[5,6]

作为文件提及:

地图(func,itoser [,schunksize]))

A parallel equivalent of the map() built-in function (it supports only one iterable argument though). It blocks until the result is ready.

This method chops the iterable into a number of chunks which it submits to the process pool as separate tasks. The (approximate) size of these chunks can be specified by setting chunksize to a positive integer.

in python2, mutilprocessing pool function map, i set param 'chunksize=2' ,but it does not work. i confuse what that is mean? code as follows:

from multiprocessing import Pool

import time
import os

work = [1,2,3,4,5,6]


def work_log(work_data):
    print "{} receive data: {}".format(os.getpid(), work_data)


def pool_handler():
    p = Pool(2)
    p.map(work_log, work,chunksize=2)


if __name__ == '__main__':
    pool_handler()


i receive the res as follows:

25883 receive data: 1

25884 receive data: 3

25884 receive data: 4

25883 receive data: 2

25884 receive data: 5

25884 receive data: 6

the res should be : [1,2] , [ 3,4] , [5,6]

as the file mention:

map(func, iterable[, chunksize])

A parallel equivalent of the map() built-in function (it supports only one iterable argument though). It blocks until the result is ready.

This method chops the iterable into a number of chunks which it submits to the process pool as separate tasks. The (approximate) size of these chunks can be specified by setting chunksize to a positive integer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文