我已经使用dask
包delayed
和compute
方法构建了 Python 2.7 代码。
这是我的代码的一个小例子:
from dask import delayed, compute
import time
class simulation():
# defines simulation parameters
def __init__(self,x):
self.x = x
jobs = range(50) # sample jobs
def simulate(sim):
# sample simulation function
time.sleep(0.01*sim.x)
return sim.x**2
def save_results(results):
# sample dump results function
print results
return []
results = []
for i,j in enumerate(jobs) :
sim = simulation(j)
res = delayed(simulate)(sim) # running simulation given input params as job
results.append(res)
if i%10==0 or i==len(jobs)-1: # evaluation every 50 steps
results = compute(results)[0] # dask execution
results = save_results(results) # storing results to DB and returning empty list
出于某种原因,此代码在 windows 上的 anaconda 设置上完美运行,但在 Linux 上失败。
我得到的错误是:
--> 134 res = delayed(simulate)(simulation) 135 136
...
/home/user/.conda/envs/neuro/lib/python2.7/abc.pyc in __subclasscheck__(cls, subclass) 159 return False 160 # Check the subclass hook --> 161 ok = cls.__subclasshook__(subclass) 162 if ok is not NotImplemented: 163 assert isinstance(ok, bool) /home/user/.conda/envs/neuro/lib/python2.7/site-packages/backports_abc.pyc in __subclasshook__(cls, C) 64 def __subclasshook__(cls, C): 65 if cls is Generator: ---> 66 mro = C.__mro__ 67 for method in required_methods: 68 for base in mro: AttributeError: class simulation has no attribute '__mro__'
将软件包 ( dask
) 更新到最新版本并没有帮助。
关于如何修复它的任何建议?
谢谢