如何从用户定义的包Python导入ipyparallel函数

时间:2017-06-07 17:25:21

标签: python ipython-parallel

我有一个python脚本,其中包含许多用户定义的函数,我已在本地设置了一个包。我可以运行input_processing.py脚本中的所有函数,除了我打算并行运行的函数。

以下是导入包的代码......

import attrition25.input_processing as attrition

我收到此错误...

NameError: name 'dview' is not defined

这就是input.processing.py ...

中的函数
@dview.parallel(block=True)
def get_dmat_elements(a, b, c):
    d = a + b + c
    return(d)

我尝试了sync_imports()并查看了@interactive装饰器,但我无法到达任何地方。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

虽然我没有完全获得范围,但为了让函数工作,我不得不将它添加到input_processing.py脚本的开头......

import ipyparallel as ipp
# Create directView Instance for Parallel Processing
c = ipp.Client()
dview = c[:] # use all engines

我在测试的Jupyter笔记本中有相同的代码块,但是没有用。

希望这可以帮助那些人。

干杯!