尝试ipyparallel,并在将代码推送到我的引擎的最早阶段陷入困境。启动我的引擎:
ipcluster start -n 4
然后尝试将东西放在引擎上:
import ipyparallel as ipp
from scipy.interpolate import interp1d
import numpy as np
class supersimple:
def __init__(self):
self.dummy = 5
def __call__(self, x):
return self.dummy + x
def simplefunc(x):
return x
if __name__ == '__main__':
rc = ipp.Client()
dview = rc[:]
# Instatiate my class and put it on an engine
myclass = supersimple()
rc[0].push({'myclass': myclass})
# Put my function on the engine
rc[0].push({'simplefunc': simplefunc})
# Put a scipy object on the engine
x = np.arange(10)
y = 3.+3.3*x
otherobj = interp1d(x, y)
rc[0].push({'otherobj': otherobj})
# Check that everything is on the engine
print(rc[0]['otherobj'])
print(rc[0]['simplefunc'])
print(rc[0]['myclass'])
结果:
<scipy.interpolate.interpolate.interp1d object at 0x117913b38>
<function simplefunc at 0x117923b70>
和
blah blah, boring traceback
ipyparallel.error.RemoteError: NameError(name 'myclass' is not defined)
所以,有两个问题: 1)如何让我的课程进入引擎?
(并不重要,但我很好奇)2)为什么当我尝试将东西推送到引擎并且它失败时,是否有任何错误?似乎奇怪的代码只是在没有做某事时说出一些麻烦。