[Python-Dev] Re: pickle me, Elmo? (weakref feature request)
Guido van Rossum
guido@python.org
Mon, 10 Feb 2003 14:48:04 -0500
> Is this the right time to post a feature request ?
To get something into Python 2.3's pickling, it's now or never.
> It's about pickling weakrefs:
>
> let's assume i 've created 3 class instances
>
> >>> class A:
> ... pass
>
> >>> a = A()
> >>> b = A()
> >>> c = A()
> >>> a.b = b #put b into a
> >>> a.ref_b = weakref.ref(b) #weakref to b
> >>> a.ref_c = weakref.ref(c) #weakref to c
>
> now i pickle around
>
> >>> data = pickle.dumps(a)
> >>> new_a = pickle.loads(data)
>
> now i would like to have:
>
> new_a is my unpickled a
> new_a.b is my unpickled b
> new_a.ref_b is an weakref to new_a.b
> new_a.ref_c is an dead weakref
> (c was not pickled because it's just weakly-referenced)
>
>
> weakrefs are not supported by the default, but this kind of 'support'
> could not (i didn't get it ;) be added using the copy_reg module,
> but it seems to be very useful;
Your grammar here seems garbled; I'll just take it to mean that you'd
like the example to work. ;-)
> weakrefs could used as an "pickling-barrier"...
>
> what do you think?
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...
IOW, I don't see it happening.
--Guido van Rossum (home page: http://www.python.org/~guido/)