我已经设置了一个小的测试java应用程序,它在启动pyro服务器之后调用python脚本(在python中)。它工作得很好除了现在我想将python类作为参数传递给它的方法。我从python方面得到一个例外:
Pyro4.errors.SerializeError: unsupported serialized class:
com.test.pyro4.TestLog
根据pyros文档,一个类将在python中转换为dict,但我甚至无法做到这一点。
java代码:
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()
答案 0 :(得分:0)
尝试将序列化设置为pickle
:
Pyro4.config.SERIALIZER = 'pickle'
请注意,这有security implications。
这在Java中:
Config.SERIALIZER = Config.SerializerType.pickle;