On 4/5/07, Mae <[EMAIL PROTECTED]> wrote:
>
> Wow, what luck!  I've been having a sporadic "" problem, and I've just
> resigned myself to spending today to try to debug it.  Searched the
> group for exact error, found nothing, refreshed, and saw this post in
> top slot!  Kismet.

(The error is "TypeError: can't pickle function objects", per a later
email.  This error is issued by cPickle rather than pickle, but the
approach is basically the same.)

In either case, the basic problem is that pickle has to be able to
re-create the objects later, and can only do that if it knows how to
refer to the type of the thing it must create.  Pickle refuses to
serialize an object it can't be fairly sure of later de-serializing.

http://docs.python.org/lib/pickle-inst.html

Here's a quick example producing this error:

>>> import cPickle

>>> def z():
   ...:     return 1
   ...:

>>> class C(object):
   ...:     pass
   ...:

>>> c=C()


>>> cPickle.dumps(c) #works fine
'ccopy_reg\n_reconstructor\np1\n(c__main__\nC\np2\nc__builtin__\nobject\np3\nNtRp4\n.'

>>> c.x = z

>>> cPickle.dumps(c) #works fine
"ccopy_reg\n_reconstructor\np1\n(c__main__\nC\np2\nc__builtin__\nobject\np3\nNtRp4\n(dp5\nS'x'\nc__main__\nz\np6\nsb."

>>> def z(): #redefine z, which c.x refers to.
   ...:     return 2
   ...:

>>> cPickle.dumps(c) #explodes because the function referred to by c.x
no longer has a name.
...
TypeError: can't pickle function objects

--------------------

Similarly, paceman's error is something like this (starting with a new
interpreter!):

>>> import cPickle
>>> class C(object):
   ...:     pass
   ...:

>>> c=C()

>>> cPickle.dumps(c) #works fine
'ccopy_reg\n_reconstructor\np1\n(c__main__\nC\np2\nc__builtin__\nobject\np3\nNtRp4\n.'

>>> class C(object): #redefine C
   ...:     pass
   ...:

>>> cPickle.dumps(c) #fails because the class c is an instance of no
longer has a name.
...
PicklingError: Can't pickle <class '__main__.C'>: it's not the same
object as __main__.C


-----

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to