当前位置: 动力学知识库 > 问答 > 编程问答 >

multithreading - Pathos multiprocessing imported packaged are not globally loaded

问题描述:

I am using pathos multiprocessing to be able to process functions with multiple input variables of different types (numpy, gdal, lists, etc.). Problem is that my packages are not loaded when I implement my multi-core function. I know that this and this stack overflow questions are describing a similar issue. However, when I implement the solutions presented there the issue persists. Currently, multiprocessing with pathos only works when I load the packages in the function.

Do you have any idea how solve this problem?


Example

import pathos.multiprocessing as pmp

import numpy as np

def simple_func(params):

x,y=params

return np.nanmean(np.column_stack((x,y)))

if __name__ == "__main__":

x=np.arange(9).reshape(3,-1)

y=np.ones(np.shape(x))

params=[[x,y],[x*2,y*2],[x*3,y*3]]

p = pmp.ProcessingPool(6)

p.map(simple_func, params)

Error

NameError: global name 'np' is not defined

分享给朋友:
您可能感兴趣的文章:
随机阅读: