[Stackless] pickling code objects
Kristján Valur Jónsson
kristjan at ccpgames.com
Fri May 25 12:30:14 CEST 2007
Aha, well, yes pickle works, but reduce ex doesn´t:
>>> f.func_code.__reduce_ex__(2)
(<function __newobj__ at 0x00C8F7C8>, (<type 'code'>,), None, None, None)
so far so good, but you can't continue and pickle the "code" type:
>>> pickle.dumps(f.func_code.__reduce_ex__(2))
will return an error, because "code" isn´t found in __builtin__ where
it claims to exist. And anyway, the "code" constructor takes some
12 arguments, obviously missing.
We use the __reduce_ex__() protocol to implement our own pickling.
I don't know how pickle(dumps) manages this without invoking __reduce_ex__()
In stackles 2.3 __reduce_ex__(2) would return proper stuff, including the
stackless.code type which was found in module stackless, and proper
initialization tuple.
The current behavious is consistent with vanilla python, though.
Kristjan
> -----Original Message-----
> From: stackless-bounces at stackless.com [mailto:stackless-
> bounces at stackless.com] On Behalf Of Richard Tew
> Sent: Thursday, May 24, 2007 18:59
> To: Kristján Valur Jónsson
> Cc: stackless at stackless.com
> Subject: Re: [Stackless] pickling code objects
>
> On 5/24/07, Kristján Valur Jónsson <kristjan at ccpgames.com> wrote:
> > After upgrading eve to stackless 2.5.1 (or rather, as a part of this
> > integration) I discovered that code objects are not pickleable.
>
> Python 2.5.1 Stackless 3.1b3 060516 (release25-maint:55039:55048, May
> 1 2007, 14:13:4) [MSC v.1310 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> def f():
> ... print 1
> ...
> >>> import pickle
> >>> pickle.dumps(f.func_code)
> "cstackless._wrap\ncode\np0\n(I0\nI0\nI1\nI67\nS'd\\x01\\x00GHd\\x00\\x
> 00S'\np1\n(NI1\ntp2\n(t(tS'<stdin>'\np3\nS'f'\np4\nI1\nS'\\x00\\x01'\np
> 5\n(t(ttp6\nRp7\n(
> tb."
> >>>
>
> Is there a reproducibility case for the problem you are experiencing?
>
> Cheers,
> Richard.
>
> _______________________________________________
> Stackless mailing list
> Stackless at stackless.com
> http://www.stackless.com/mailman/listinfo/stackless
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list