[Tutor] Unpickleable object error

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Thu, 6 Sep 2001 14:06:54 -0700 (PDT)


On Thu, 6 Sep 2001, Sheila King wrote:

>     def __init__(self, id, passwd, email, mssgList, lastmssg, caller = None):
>         self.lockfile = MutexFile.MutexFile('userdb.lck')
>         self.myfilename = 'users'
>         self.id = id
>         self.passwd = passwd
>         self.email = email
>         self.mssgList = mssgList
>         self.lasmssg = lastmssg

[some text cut]

> Traceback (most recent call last):
>   File "e:\apache\cgi-bin\pibby\init.py", line 20, in ?
>     mainBoard.addUser(admin)
>   File "e:\apache\cgi-bin\pibby\pbbclass.py", line 34, in addUser
>     userdb[user.id] = user
>   File "E:\PYTHON\PYTHON21\lib\shelve.py", line 76, in __setitem__
>     p.dump(value)
> cPickle.UnpickleableError: Cannot pickle <type 'PyHANDLE'> objects


I suspect it might have to do with the MutexFile object --- the error
about a PyHANDLE sounds really specific to a Win32 thing:

 http://aspn.activestate.com/ASPN/Python/Reference/Products
       /ActivePython/PythonWin32Extensions/PyHANDLE.html

and since you mentioned earlier that MutexFile tries to do things
uniformly on Windows and Unix, that implies that MutexFile could be the
source of the pickle bug.

How are you implementing MutexFile?  Can you check to see if you can
pickle a MutexFile?  If not, you may need to tell pickle not to touch your
self.lockfile --- that is, you might need to give pickle some specific
instructions when pickling/unpickling a MutexFile.

Take a look at:

    http://www.python.org/doc/lib/module-pickle.html

In particular, you might need to define __getstate__() and __setstate__()
methods in either MutexFile or your userfile class to take this into
account.


Hope this helps!