#28 cPickle


The string produced by cPickle differs for functions
bound by psyco and those that are not. Python is able
to load both types versions of the pickled objects, but
this causes problems if you're using the string as a
key in a DB. This was done on Windows XP with Python
2.3.3 and Psyco 1.1.1

>>> import psyco
>>> def a():
return cPickle.dumps(('a', None, None),
>>> def b():
return cPickle.dumps(('a', None, None),
>>> psyco.bind(a)
>>> a()
>>> b()


  • Nobody/Anonymous

    Logged In: NO

    It seems that you should not be using cPickle for this
    purpose. It does "optimizations" based on reference
    counters, which means that it will not always give the same
    string for the same input. For example (without Psyco):

    >>> cPickle.dumps("hello")
    >>> cPickle.dumps("he" + "llo")

    The problem you have comes from the fact that the objects
    cPickle sees do not have exactly the same reference counters
    when called from Psyco or from Python. There is no easy
    fix. You can try to forbit Psyco to compile the function
    that calls cPickle.dumps, but keep in mind that using
    cPickle for this purpose gives unguaranteed results anyway.

    This should probably get mentionned in the cPickle module
    documentation. (If you only have simple non-recursive
    built-in objects, try using the marshal module instead.)

  • Armin Rigo

    Armin Rigo - 2004-01-14
    • status: open --> closed-invalid

Log in to post a comment.