msg19940 - (view) |
Author: Toon Verstraelen (tovrstra) |
Date: 2004-02-08 15:55 |
My python version: Python 2.3.3 (#1, Jan 25 2004, 21:45:01) [GCC 3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r3, propolice)] on linux2 Please try the example. That will explain a lot. The problem is that not all new style class instances are picklable. In my example a class is derived from a list and a base class. The list-descendant contains an instance of the base class, which has a reference to the list containing it. with cPickle things work fine, but not for the normal pickle routines class subitem: def __init__(self, parent): self.parent = parent if parent != None: parent.append(self) class group(subitem, list): def __init__(self, parent): subitem.__init__(self, parent) g = group(None) s = subitem(g) import cPickle print cPickle.dumps(g) import pickle print pickle.dumps(g) |
|
|
msg19941 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2005-10-01 13:40 |
Logged In: YES user_id=1188172 Verified in 2.5cvs. |
|
|
msg58057 - (view) |
Author: Alexandre Vassalotti (alexandre.vassalotti) *  |
Date: 2007-12-01 17:35 |
Please assign this bug to me. Note that neither cPickle or pickle is able to load the stream generated by cPickle correctly: >>> g = group(None) >>> subitem(g) >>> g[0].parent is g True >>> gp = cPickle.loads(cPickle.dumps(g)) >>> gp[0].parent is gp False I don't think that will be easy to fix, but I will try to see what I can do. |
|
|
msg82010 - (view) |
Author: Daniel Diniz (ajaksu2) *  |
Date: 2009-02-14 11:31 |
Confirmed on trunk. |
|
|
msg114318 - (view) |
Author: Mark Lawrence (BreamoreBoy) * |
Date: 2010-08-19 05:38 |
This is still a problem with 2.6 and 2.7. I don't know how to test this with py3k as cPickle doesn't exist, can someone advise, thanks. |
|
|
msg188288 - (view) |
Author: Alexandre Vassalotti (alexandre.vassalotti) *  |
Date: 2013-05-03 01:33 |
I fixed this while working on PEP 3154 [http://hg.python.org/features/pep-3154-alexandre/rev/eed9142d664f]. The relevant piece is @@ -420,7 +424,13 @@ class _Pickler: write(REDUCE) if obj is not None: - self.memoize(obj) + # If the object is already in the memo, this means it is + # recursive. In this case, throw away everything we put on the + # stack, and fetch the object back from the memo. + if id(obj) in self.memo: + write(POP + self.get(self.memo[id(obj)][0])) + else: + self.memoize(obj) # More new special cases (that work with older protocols as # well): when __reduce__ returns a tuple with 4 or 5 items, It would be pretty easy to backport this to 2.7 and 3.3. It is also good to mention that that only protocol 0 and 1 are affected. |
|
|
msg253435 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-10-25 19:46 |
Here is a patch that backports recursive objects handling to 2.7. |
|
|
msg254003 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-11-03 16:53 |
Could you please make a review Alexandre? |
|
|
msg254091 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-11-05 08:08 |
Updated patch addresses Alexandre's comments. |
|
|
msg254191 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-11-06 13:32 |
Here is revised patch that uses different approach to tests. cPickleFastPicklerTests overridden old recursive tests to check that they raises an exception. The patch extends this to new recursive tests. |
|
|
msg254264 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2015-11-07 09:17 |
New changeset 9ad1fd251ddf by Serhiy Storchaka in branch '2.7': Issue #892902: Fixed pickling recursive objects. https://hg.python.org/cpython/rev/9ad1fd251ddf New changeset 2071d16ed5e6 by Serhiy Storchaka in branch '3.4': Issue #892902: Added new tests for pickling recursive collections. https://hg.python.org/cpython/rev/2071d16ed5e6 New changeset f33ce913220b by Serhiy Storchaka in branch '3.5': Issue #892902: Added new tests for pickling recursive collections. https://hg.python.org/cpython/rev/f33ce913220b New changeset 2c81a883d8ca by Serhiy Storchaka in branch 'default': Issue #892902: Added new tests for pickling recursive collections. https://hg.python.org/cpython/rev/2c81a883d8ca |
|
|
msg254265 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-11-07 09:22 |
Thank you for your review Alexandre. In 3.x old tests test_recursive_set and test_recursive_frozenset now are implemented in test_recursive_set_and_inst and test_recursive_frozenset_and_inst. Instead new test_recursive_set now tests protocol 4 ability of pickling recursive sets itself. |
|
|
msg254291 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2015-11-07 18:05 |
New changeset 77184a429dae by Serhiy Storchaka in branch '2.7': Issue #892902: Disable newly added tests in test_xpickle. https://hg.python.org/cpython/rev/77184a429dae |
|
|