繁体   English   中英

Python多重处理。传递参数中矩阵大小的池限制

[英]Python multiprocessing.Pool limit on matrix size in passed arguments

我最近发现multiprocessing.Pool中的apply_async方法对args=()传递的参数的大小有限制。 真的是这样吗,还是我做错了什么?

我已经附上了一个示例代码,其中我仅在调用的函数中打印矩阵的形状。 如您所见,在大小为21000 ,不再调用该函数(并且不会引发异常或警告:\\)

import numpy as np
from multiprocessing import Pool

def _mp_print_size(mat):
    try:
        print 'Mat size [%d %d]' % (mat.shape[0], mat.shape[1])
    except Warning as w:
        print w
    except Exception as e:
        print e

def diff_sizes(size):
    print 'Running with size ', size
    mat = np.ones([size, size])

    pool = Pool(2)
    for i in range(2):
        pool.apply_async(func=_mp_print_size, args=(mat, ))

    pool.close()
    pool.join()


if __name__ == '__main__':
    sizes = np.arange(1000, 1000000, 10000)
    for s in sizes:
        diff_sizes(s)

打印出来的是:

Running with size  1000
Mat size [1000 1000]
Mat size [1000 1000]
Running with size  11000
Mat size [11000 11000]
Mat size [11000 11000]
Running with size  21000
Running with size  31000
Running with size  41000
Running with size  51000
Running with size  61000

抱歉,如果有人提出此问题,请联系我以前的实例,因为我自己找不到它。

由于multiprocessing.Pool.apply/map在后台使用Queue ,因此它看起来像是http://bugs.python.org/issue8426的体现。

我将搜索并在multiprocessing相关调用中添加调试打印,以检查是否正在调用与错误讨论中相同的事物和具有相同大小的参数。

如果真是这样,这将保证产生另一个错误,以使multiprocessing检查有效负载大小并将传输分成多个块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM