Python dispy - 保留依赖项的包名称

时间:2016-06-30 17:29:45

标签: python parallel-processing distributed-computing dispy

有没有办法保留通过dispy依赖功能传输的python模块的包名? 这将允许在使用和不使用dispy上下文调用时以相同的方式使用包/模块。

简单示例:

模块mypackage.dispytestDepends:

def myFun():
    return "Foo"

主要模块,因为我希望它(不起作用):

def dependsFunTask(): #works only when called without dispy
    import mypackage.dispytestDepends 
    ret = mypackage.dispytestDepends.myFun()
    return ret

import dispy
if __name__ == '__main__':
    cluster = dispy.JobCluster(dependsFunTask,depends = mypackage.dispytestDepends) # doesn't work
    job = cluster.submit()
    output = job()
    print output ### output is None
    mypackage.dependsFunTask() # works

工作,但丑陋的版本,因为我有很多代码需要重写:

def dependsFunTask(): #only works when called through dispy
    import dispytestDepends
    ret = dispytestDepends.myFun()
    return ret

import dispy

if __name__ == '__main__':
    cluster = dispy.JobCluster(dependsFunTask,depends = mypackage.dispytestDepends) # works
    job = cluster.submit()
    output = job()
    print output ### output is "Foo"
    dependsFunTask() # doesn't work

1 个答案:

答案 0 :(得分:1)

这应该适用于当前版本的dispy。另请参阅https://github.com/pgiri/dispy/issues/43