PyCode serialization was fixed for 2.5.2 beta 1; see http://bugs.jython.org/issue1601

However it's somewhat tricky to use because of the fact that such code objects will be in a separate classloader. Cliff''s solution sidesteps this issue, at the cost of geting into Jython's internals, which are subject to change. Probably the better solution is to subclass ObjectOutputStream and ObjectInputStream with annotateClass and resolveClass methods. See Lib/test/test_java_integration.SerializationTest which implements this, albeit with just the in-memory case (so much simpler). I'd also recommend Eamonn McManus' blog post for more background on what's happening here: http://weblogs.java.net/blog/emcmanus/archive/2007/04/cloning_java_ob.html

- Jim

On Wed, Aug 11, 2010 at 9:58 AM, Cliff Hill <xlorep@darkhelm.org> wrote:
Ok, I found a way to serialize compiled Jython code, and explained it in my blog post (here), hopefully it will work for others. I've been able to successfully serialize a compiled Jython script, and be able to execute it in a separate process, all within the Google AppsEngine for Java environment (but there really is no reason it can't work elsewhere -- all I'm using is standard Java libraries and components from Jython's library).

I would have posted the solution directly into this group, but my source code was simply too big to post here.

On Sun, Apr 18, 2010 at 2:39 PM, Tony Locke <tlocke@tlocke.org.uk> wrote:
On 14 April 2010 00:46, Tom Nichols <tmnichols@gmail.com> wrote:
> Can someone give an example of how one might pickle a PyCode object
> (from Java)?  I'm interepreting python scripts (in Java) and I'd like
> to memcache the compiled result and then retrieve and run it as
> opposed to re-evaluating the source the next time the same script is
> used.
>
> Considering that PyCode specifically implements Serializable,
> shouldn't the org.python.core.CompilerFlags field be marked as
> transient in order to allow PyCode to serialize successfully?  Or is
> it more complicated than that?

I've come to the conclusion that it's a bug, so I've reported it at:

http://bugs.jython.org/issue1601

I don't know enough about Jython to submit a patch. It could be that
the right thing to do is to make the CompilerFlags class serializable,
or the right thing could be to mark the compiler flags field
transient, or none of the above!

>
> I'd be happy to raise an issue if it's just a matter of marking that
> field transient.
>
> Thanks.
> -Tom
>
>
> On Fri, Apr 9, 2010 at 8:13 AM, jython-users-request
> <jython-users-request@lists.sourceforge.net> wrote:
>> Date: Thu, 8 Apr 2010 21:24:04 -0500
>> From: Marc Downie <marc@openendedgroup.com>
>> Subject: Re: [Jython-users] Serializing a PyCode object
>> To: Cliff Hill <xlorep@darkhelm.org>
>> Cc: Jython-users@lists.sourceforge.net
>> Message-ID:
>>        <w2kb722ae3d1004081924o6e75aaa7wb85e9a72dd502b95@mail.gmail.com>
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>> On Thu, Apr 8, 2010 at 8:45 PM, Cliff Hill <xlorep@darkhelm.org> wrote:
>>
>>> *Why not use Python's own pickle for it? I'm not entirely certain that
>>> Python classes could be serialized using Java's serialization, but pickling
>>> will work, and is the python equivalent (more or less).*
>>
>>
>> Unless I'm completely mistaken, Pickle won't serialize arbitrary user
>> defined classes (it serializes code by name rather than by value). So it
>> might not be what the original poster wants.
>>
>> (People have bumped into this before, for example:
>>
>> http://code.activestate.com/recipes/572213-pickle-the-interactive-interpreter-state/
>>
>> But I have no experience with this approach and it's definitely hackish.)
>>
>> best,
>>
>> Marc.
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> Jython-users mailing list
> Jython-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jython-users
>

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users



--
"I'm not responcabel fer my computer's spleling errnors" - Xlorep DarkHelm
Website: http://darkhelm.org

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users