Shelve doesn't appear to restore references properly????
Muppet
google.com at magicdb.com
Sat Mar 8 22:06:35 EST 2003
> A shelved object cannot share data with another shelved object. That
> is a known and accepted limitation of shelves, and, because of how
> shelves work, is not likely to go away.
Ahhhh.... Ouch.
> Yes, you can pickle a dict. See the cPickle module. I daresay you
> should have done it that way from the start: unless there are too many
> muppets to fit in memory, or you need fast lookup of only a few items,
> there is not much benefit of a shelf over a pickle. (Because the
> objects share data, the latter possibility seems unlikely to me.)
I'm assuming you mean pickle a dict of all the "muppets" then restore
that entire pickle at the start of each session?
That's probably going to be too slow: this is going to end up running
as a CGI.
> Nevertheless, you know your code better than I. If pickling a dict
> won't do, then you can work around the limitation of shelve using the
> __getstate__ and __setstate__ methods. I will be happy to elaborate
> if you wish.
Please. I've spent most of the evening mucking around with
__getstate__ and __setstate__ and the best I've been able to manage is
a "borg" object, where the __dict__ attributes of the various restored
objects are the same, which isn't really progress. I just can't figure
out how to actually get shared objects back from the pickle, no matter
how I try.
This is really driving me nuts!
More information about the Python-list
mailing list