我已經設置了一個小的測試java應用程序,它在啓動pyro服務器(在python中)後調用python腳本。除了現在我想把一個對象作爲參數傳遞給它的方法,它工作得很好。我從Python端說法例外:如何使用pyro以對象作爲參數調用python
Pyro4.errors.SerializeError: unsupported serialized class:
com.test.pyro4.TestLog
根據火焰兵文檔類將得到轉換爲在python的字典,但我甚至不能走到這一步。
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();
蟒蛇服務器代碼:
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()
代碼已被更新,以顯示它現在是如何工作的。對象是在python端創建的,然後通過java端的代理請求,設置值,然後用於調用python方法。 – user1584120
我說得太快了。以上代碼不起作用。獲取以下錯誤:TypeError:'float'對象不可迭代。我已經把所有的參數從調用中剝離出來,只留下對象,它似乎是什麼? – user1584120