473,473 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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

What are my options?

alex

--
Alex Polite
http://polite.se
Jul 18 '05 #1
5 2216
Hi,

* Alex Polite <m4@polite.se> [26 May 2004 14:22:21 GMT]:
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
--
pub 1024D/6EBDA359 1999-09-20 Lutz Horn <lu*******@web.de>
Key fingerprint = 438D 31FC 9300 CED0 1CDE A19D CD0F 9CA2 6EBD A359
sub 2048g/EA8CFEDE 2000-03-09
Jul 18 '05 #2


On ons, maj 26, 2004 at 04:34:00 +0200, Lutz Horn wrote:
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

--
Alex Polite
http://polite.se
Jul 18 '05 #3
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:ti****@stackless.com>
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/
Jul 18 '05 #4
On ons, maj 26, 2004 at 02:22:21 +0000, Alex Polite wrote:
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

--
Alex Polite
http://polite.se
Jul 18 '05 #5
Alex Polite wrote:
On ons, maj 26, 2004 at 02:22:21 +0000, Alex Polite wrote:
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.


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:ti****@stackless.com>
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/
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Richard Kessler | last post by:
I am attempting a GUI using BOA Constructor. I have some simple code to pickle an object, but for some reason when I use cPickle it hangs the system, but pickle works just fine. I do not have a...
2
by: LoserInYourFaceEngineer | last post by:
Hello All: I'm having trouble with a recursive function. The function is supposed to identify nested folders in a hierarchical folder structure. The function "searchForFolders()" is...
1
by: Glen Able | last post by:
Hi, I have a collection of lists, something like this: std::list<Obj*> lists; Now I add an Obj to one of the lists: Obj* gary; lists.push_front(gary);
14
by: MLH | last post by:
GHudson has working procedures posted at http://www.access-programmers.co.uk/forums/showthread.php?t=66320 They work. Relationships, however, and some minor default settings are not preserved....
2
by: Peder Y | last post by:
My code is something like this: --------------- Image img = Image.FromFile("somefile.bmp"); FileStream fStream = new FileStream("someBinaryFile.dat"); BinaryWriter bw = new...
9
by: Crirus | last post by:
dim pp as string pp="{X=356, Y=256}{X=356, Y=311.2285}{X=311.2285, Y=356}{X=256, Y=356}{X=200.7715, Y=356}{X=156, Y=311.2285}{X=156, Y=256}{X=156, Y=200.7715}{X=200.7715, Y=156}{X=256,...
6
by: mitola | last post by:
i want to ask how can you save like for example char , or a string in c++ for multiple uses. like when you close the program and when you reopen it you can see what you entered. i need this to know...
1
by: rekkufa | last post by:
I am currently building a system for serializing python objects to a readable file-format, as well as creating python objects by parsing the same format. It is more or less complete except for a...
16
by: Wayne | last post by:
I've read that one method of repairing a misbehaving database is to save all database objects as text and then rebuild them from the text files. I've used the following code posted by Lyle...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.