|
From: Vu P. <ph...@gm...> - 2015-11-30 16:06:12
|
Hi all, I have an application where I serialize a python function, send it to the server (running in scala), then execute that function with Jython (release 2.7), get the result and do something else with it. Apparently if the function has some return command or "jump", it will fail. But the same piece of code works well in Python 2.7. This works well in Python: https://gist.github.com/phvu/79a0ffdc481ec0622f4a But exactly the same piece of code doesn't work in Scala shell: https://gist.github.com/phvu/9442ea60cd6c14c6859f For Googlers, the exception was: java.lang.ArrayIndexOutOfBoundsException: 4 at org.python.core.PyBytecode.interpret(PyBytecode.java:961) at org.python.core.PyBaseCode.call(PyBaseCode.java:70) at org.python.core.PyBaseCode.call(PyBaseCode.java:138) at org.python.core.PyFunction.__call__(PyFunction.java:413) at org.python.pycode._pyx0.f$0(<string>:9) In case you wonder how code_string was created: https://gist.github.com/phvu/357c2fd2bca8a08fab2f My question is: Is this a bug or a "feature"? When the serialized function is "simple" (like lambda x: x/2.), then jython works. But apparently it doesn't work when there is a return or a jump in the function. I know "compiler", "marshal" and such are not very well supported in jython, but I used cPickle to serialize the bytecode, and it works in Python, so I expect it to work in jython too. Any help is appreciated. Cheers, -- PHAM Hoai Vu LinkedIn: linkedin.com/in/vuphoai |