[Python-Dev] Re: pickle me, Elmo? (weakref feature request)
Arne Koewing
ark@gmx.net
Tue, 11 Feb 2003 12:10:29 +0100
Jeremy Hylton <jeremy@zope.com> writes:
> On Mon, 2003-02-10 at 14:48, Guido van Rossum wrote:
>> I brainstormed for a few minutes with Fred Drake, the weakref expert,
>> but we saw many obstacles to implementing it. It would be A Major
>> Project to implement this: it would require adding new methods to
>> weakref objects, and new pickling codes, and an extension to the
>> pickling and unpickling engines...
>>
>
> I suspect that something like this feature could be implemented using
> persistent_id() and persistent_load(). The persistent_id() could do
> something special for weak references, returning a persistent id that is
> the id() of the referenced object. The persistent_load() function could
> check for one in the memo and create a new weakref if it exists;
> otherwise, it would return None.
>
> The one hitch is that the only reference to an object might occur after
> the weakref. The unpickler wouldn't know that the object occurred
> later. Not sure how to finesse this problem; it seems to require a
> second pass over the pickle stream at some point, which is a major
> rewrite. Perhaps the persistent_load() always returns a proxy object
> that isn't a weakref, but has the same interface. When the unpickler is
> done, it gives all these objects a chance to check the memo for the real
> objects.
>
That sounds somewhat familiar to me...
I've tried to implement this for the pickle module, but I've never
got it finished.
The next ten days I'll be to busy to reinvestigate this.
When I've more time (in eleven days :-) I'll try to really
understand the weakref and Pickle/cPickle module implementations.