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

Alain Poirier alain.poirier at net-ng.com
Thu Nov 8 12:43:27 CET 2007


Hi,

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__");
         */





More information about the Stackless mailing list