Deserializing python fuction with cPickle in Jython

Vu Pham <[email protected]>
Newsgroups gmane.comp.lang.jython.user
Message-ID <CAFhKpXFLDg0rkZc32m-NtWn1yoGtK269i6m_2RVCCr7mprnMxQ@mail.gmail.com>
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

------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140

_______________________________________________
Jython-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.