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