我已经设置了一个小型测试 java 应用程序,它在启动 pyro 服务器(在 python 中)后调用 python 脚本。它工作得很好,除了现在我想将 python 类作为参数传递给它的方法。我从python方面得到一个例外说:
Pyro4.errors.SerializeError: unsupported serialized class:
com.test.pyro4.TestLog
根据 pyros 文档,一个类将被转换为 python 中的字典,但我什至无法做到这一点。
爪哇代码:
NameServerProxy ns = NameServerProxy.locateNS("localhost");
PyroProxy remotePluginObject = new PyroProxy(ns.lookup("plugin"));
int length = 5;
double[] values = new double[] { 0.5, 0.3, 0.6, 05, 0.4 };
double a = 6.94;
double b = 2.17;
remoteObject = new PyroProxy(ns.lookup("test.object"));
remoteObject.call("setValues", values, length);
Object result = remoteObject.call("calculate", remoteObject, a, b);
System.out.println(result.toString());
remotePluginObject.close();
remoteObject.close();
ns.close();
python服务器代码:
class TestObject(object):
values=[]
length=0
def setValues(self, valuesArray, lengthValue):
values=valuesArray
length=lengthValue
class Plugin(object):
def calculate(self, obj, a, b):
result = example.calculate(obj, a, b)
return result
plugin=Plugin()
obj=TestObject()
daemon=Pyro4.Daemon()
ns=Pyro4.locateNS()
pluginURI=daemon.register(plugin)
ns.register("plugin", pluginURI)
objURI=daemon.register(obj)
ns.register("test.object", objURI)
daemon.requestLoop()