python2 mutilprocessing池图功能中的参数块大小的含义是什么?
在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论