[Stackless] Error for the pickle of a module in a package + patch

Kristján Valur Jónsson kristjan at ccpgames.com
Thu Nov 8 16:13:17 CET 2007


I have submitted my fix.
Btw, here is a python only unitest for the crash:

#my crashing code


import stackless
stackless.enable_softswitch(0)

def sleeper():
        t = stackless.tasklet().capture()
        t.remove()

t = stackless.tasklet(sleeper)
t()
t.run()

K

> -----Original Message-----
> From: stackless-bounces at stackless.com [mailto:stackless-
> bounces at stackless.com] On Behalf Of Richard Tew
> Sent: 8. nóvember 2007 14:02
> To: Alain Poirier
> Cc: stackless at stackless.com
> Subject: Re: [Stackless] Error for the pickle of a module in a package +
> patch
>
> On 11/8/07, Alain Poirier <alain.poirier at net-ng.com> wrote:
> > When a module in a package is pickled then unpickled, the result is
> > the package, not the module:
> >
> > Python 2.5.1 Stackless 3.1b3 060516 (release25-maint, Oct 18 2007,
> 22:24:34)
> > [GCC 3.4.6 (Gentoo 3.4.6-r2, ssp-3.4.6-1.0, pie-8.7.10)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> > >>> import cPickle
> > >>> import xml.sax
> > >>> m = xml.sax
> > >>> print "Before :", hasattr(m, 'parse')
> > Before : True
> > >>> m = cPickle.loads(cPickle.dumps(m))
> > >>> print "After :", hasattr(m, 'parse')
> > After : False
> > >>> m
> > <module 'xml' from '/opt/stackless_ori/lib/python2.5/xml/__init__.pyc'>
> >
> >
> > because the pickle engine do a `__import__('xml.sax')` instead of a
> > `__import__('xml.sax', fromlist=(''))`
> >
> >
> > The following patch solves the problem:
> >
> > --- stackless-251-export/Stackless/pickling/prickelpit.c        2007-05-
> 01
> > 12:25:50.000000000 +0200
> > +++ stackless-251-export.new/Stackless/pickling/prickelpit.c    2007-11-
> 07
> > 16:20:07.000000000 +0100
> > @@ -1181,7 +1181,7 @@
> >                 if (import == NULL)
> >                         return NULL;
> >         }
> > -       return Py_BuildValue("(O(s))", import, name);
> > +       return Py_BuildValue("(O(s()()(s)))", import, name, "");
> >         /* would be shorter, but the search result is quite arbitrary:
> >                 tup = PyObject_GetAttrString(m, "__name__");
> >          */
>
> Thanks for the patch.  There's another pickling related patch from a
> few weeks ago which needs to go in as well.  Once Kristjan Valur's new
> crash fix is in along with these, it will probably be worth doing a
> new release of Stackless.
>
> Cheers,
> Richard.
>
> _______________________________________________
> Stackless mailing list
> Stackless at stackless.com
> http://www.stackless.com/mailman/listinfo/stackless





More information about the Stackless mailing list