0

有没有办法保留通过 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
4

1 回答 1

1

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

于 2016-07-13T12:53:03.377 回答