[英]How to import ipyparallel function from user defined package, Python
I have a python script that contains a number of user defined functions that I have set up a as package locally. 我有一个python脚本,其中包含许多用户定义的函数,这些函数已在本地设置为as包。 I can run all of the functions in the input_processing.py script except for the one that I intend to run in parallel.
我可以运行input_processing.py脚本中的所有功能,但我打算并行运行的功能除外。
Here is the code that imports the package... 这是导入包的代码...
import attrition25.input_processing as attrition
I get this error... 我收到此错误...
NameError: name 'dview' is not defined
This is what the function looks like in input.processing.py... 这就是input.processing.py ...中的函数外观
@dview.parallel(block=True)
def get_dmat_elements(a, b, c):
d = a + b + c
return(d)
I tried sync_imports() and looked at the @interactive decorator, but I couldn't get anywhere. 我尝试了sync_imports()并查看了@interactive装饰器,但我什么也没找到。 Any help would be appreciated.
任何帮助,将不胜感激。
Although I don't completely get the scoping, to get the function to work, I had to add this to the beginning of the input_processing.py script... 尽管我没有完全了解范围,但为了使函数正常工作,我不得不将其添加到input_processing.py脚本的开头...
import ipyparallel as ipp
# Create directView Instance for Parallel Processing
c = ipp.Client()
dview = c[:] # use all engines
I have the same exact block of code in the Jupyter Notebook where I am testing, but that did not work. 我在进行测试的Jupyter Notebook中具有完全相同的代码块,但这没有用。
Hopefully this helps someone out there. 希望这可以帮助某个人。
Cheers! 干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.