本文介绍了Python的多进程模块(带有莳萝)给出了无用的AssertionError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了dill/pathos及其依赖项(有些困难),并且我试图在多个进程上执行功能.类/属性Model(self.xml,self.exp_data,i).SSR是自定义的,并且取决于其他自定义函数的负载,因此,我为无法提供可运行的"代码而向您致歉.简而言之,它需要一些实验数据,将ODE系统与python的pysces模块集成在一起,并计算平方和(SSR).并行化此代码的目的是通过多个参数集来加快计算速度.

I have installed dill/pathos and its dependencies (with some difficulty) and I'm trying to perform a function over several processes. The class/attribute Model(self.xml,self.exp_data,i).SSR is custom made and depends on loads of other custom functions so I apologize in advance for not being able to provide 'runnable' code. In brief however, it takes some experimental data, integrates a system of ODE's with python's pysces module and calculates the sum of squares (SSR). The purpose for parallelizing this code is to speed up this calculation with multiple parameter sets.

代码:

    import multiprocess  
    def evaluate_chisq(pop):

        p = multiprocess.Pool(8)
        res= p.map(lambda i:Model(self.xml,self.exp_data,i).SSR   ,  pop)#calcualteSSR with this parameter set
        return res

我收到的错误消息是:

  File "C:\Anaconda1\lib\site-packages\multiprocess\pool.py", line 251, in map
    return self.map_async(func, iterable, chunksize).get()

  File "C:\Anaconda1\lib\site-packages\multiprocess\pool.py", line 567, in get
    raise self._value

AssertionError

然后我尝试使用map_async:

        def evaluate_chisq(pop):
            p = multiprocess.Pool(8)
            res= p.map_async(lambda i:Model(self.xml,self.exp_data,i).SSR   ,  pop)#calcualteSSR with this parameter set
            return res

返回一个<multiprocess.pool.MapResult object at 0x0000000014AF8C18>对象,当我尝试使用MapResult的`get'方法时,该对象给我同样的错误

which returns a <multiprocess.pool.MapResult object at 0x0000000014AF8C18> object which gives me the same error when I attempts to use the MapResult's `get' method

  File "C:\Anaconda1\lib\site-packages\multiprocess\pool.py", line 567, in get
    raise self._value

AssertionError

有人知道我在做什么错吗?

Does anybody know what I'm doing wrong?

推荐答案

在Windows上,您需要使用__main__中的freeze_support.

On Windows you need to use freeze_support from __main__.

请参见 https://docs.python.org/2/library /multiprocessing.html#multiprocessing.freeze_support .

这篇关于Python的多进程模块(带有莳萝)给出了无用的AssertionError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 02:21