Saving recursive objects to disc. cPickle wan't work.

A

Alex Polite

I need to put recursive data structures on disc and found out that cPickle
doesn't like recursion.

What are my options?

alex
 
L

Lutz Horn

Hi,

* Alex Polite said:
I need to put recursive data structures on disc and found out that
cPickle doesn't like recursion.

Hm, the documentation of Python 2.3.2, Section 3.14.1 "Relationship to
other Python modules" states that recursive objects, which are defined
as "objects that contain references to themselves" can't be handled by
marshal, but that pickle and cPickle should be fine: "pickle stores
such objects only once, and ensures that all other references point to
the master copy".

What exactly are your problems?

Regards
Lutz
 
A

Alex Polite

Hm, the documentation of Python 2.3.2, Section 3.14.1 "Relationship to
other Python modules" states that recursive objects, which are defined
as "objects that contain references to themselves" can't be handled by
marshal, but that pickle and cPickle should be fine: "pickle stores
such objects only once, and ensures that all other references point to
the master copy".

What exactly are your problems?

That sound promising.

I'm building a library to generate markov models from text, much like
dadadodo.

You can get the code here.

http://snippsnapp.polite.se/wiki.pl?PyDodo


When I run my testsuit that tries to pickle a generated markov model I
get this:

python test/basicsuite.py

1000
E
======================================================================
ERROR: test_pickle (__main__.BasicTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/basicsuite.py", line 73, in test_pickle
print sys.settrecursionlimit(4000)
AttributeError: 'module' object has no attribute 'settrecursionlimit'

----------------------------------------------------------------------
Ran 1 test in 0.002s



If I up the recusionlimit the testsuit will segfault.

alex
 
C

Christian Tismer

Alex Polite wrote:

....
If I up the recusionlimit the testsuit will segfault.

Then you need a Python which does not have a stack problem.

Use Stackless Python. Just don't care of what else it does,
just use it, raise the recursionlimit to whatever,
and both pickle and cPickle will run without any limit but
main memory.

Well, almost true.
The current official version is unlimited on pickle.py,
becuase the recursive calls in pickle don't involve
recursive calls in the C interpreter.
Stack protection for cPickle is in my new developer version,
which is coming soon.
It has Stack spilling for cPickle and the interpreter, so
even in the rare cases where deep recursions cannot be avoided,
the Stack is always saved and restored before overflow.
And, well, I have full thread support since Monday :))

ciao - chris

--
Christian Tismer :^) <mailto:[email protected]>
Mission Impossible 5oftware : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
 
A

Alex Polite

I need to put recursive data structures on disc and found out that cPickle
doesn't like recursion.

What are my options?

alex

Christian Tismer had the kindness to look at my code and point out
that I might want to use pickle instead of cPickle, at least if I
wanted to benefit from using stackless. Chaning from cPickle to pickle
allowed to run the code under stackless as well as under standard
python.

thanks Christian.

alex
 
C

Christian Tismer

Alex said:
Christian Tismer had the kindness to look at my code and point out
that I might want to use pickle instead of cPickle, at least if I
wanted to benefit from using stackless. Chaning from cPickle to pickle
allowed to run the code under stackless as well as under standard
python.

thanks Christian.

Although I'm happy that things work even without Stackless,
this implies that there is an incompatibility between
pickle and cPickle.
If objects are treated identically by both, that normal Python
must use even more stack space for recursive objects that
cPickle, so I'd expect it crashes earlier.

But it doesn't crash. cPickle must have a bug.

ciao - chris
--
Christian Tismer :^) <mailto:[email protected]>
Mission Impossible 5oftware : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top