[Tutor] perplexing error with shelve REVISED

Kent Johnson kent37 at tds.net
Thu Nov 1 01:12:41 CET 2007


Eric Brunson wrote:
> Orest Kozyar wrote:
>>> Please post the entire traceback (omitting duplicate lines). 
>>>     
>> Sorry, I should have included the traceback.  I've revised the sample script
>> so that it generates the traceback when run.  The sample script is at the
>> very bottom of this email.
>>   
> 
> It appears you have a cyclic reference in your doc object.  Try adding 
> "doc.unlink()" before you add it to your shelf.

I thought pickle was supposed to deal with cyclic references? The docs say,

"The pickle module keeps track of the objects it has already serialized, 
so that later references to the same object won't be serialized again. 
marshal doesn't do this.

"This has implications both for recursive objects and object sharing. 
Recursive objects are objects that contain references to themselves. 
These are not handled by marshal, and in fact, attempting to marshal 
recursive objects will crash your Python interpreter. Object sharing 
happens when there are multiple references to the same object in 
different places in the object hierarchy being serialized. pickle stores 
such objects only once, and ensures that all other references point to 
the master copy. Shared objects remain shared, which can be very 
important for mutable objects."

Kent



More information about the Tutor mailing list