473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

No limit! (was: pickle complexity limit?)

Martin v. Löwis wrote:
"Mark Hahn" <ma**@hahnca.com> writes:

I don't understand how this could happen with pickle. Isn't it supposed to
stop when it runs into an object it has already pickled?
Yes, and it does.
Couldn't it have been coded in a stackless way?


Yes, but it doesn't. Please look at save_inst implementation; it ends
with

save(stuff)
write(BUILD)

This is where the recursion happens. You run into the limit only if
you can find a path through your object graph that does not visit the
same object twice.
What do I do now? I don't want to recompile with a deeper stack as this
will obviously only help in limited cases, not solve the real problem.


There are limitations, and there are ways to cope with them. See below.
Read the pickle code, understand why it is recursive, and implement an
alternative that isn't recursive, yet preserves the original semantics
in terms of pickling order and sequence in which methods are called on
objects. When you are done, please contribute your changes back, to
sf.net/projects/python.


The reason why pickling is recursive was of course a thing
that I never really understood. For me, this is a bit like
asking for problems.
But well, the same was true with recursive destructors of
objects, until I came up with the Py_Trashcan structure.
It has been changed very much, but the idea is still alive:
try to limit recursions as much as possible.

Back to your problem: You have a chance to avoid recursions.
I had the same problem with Stackless. I support pickling of
frame chains to any extent, together with tracebacks. The
recursion problems would be there, if I didn't take some action.
ANd for Stackless, these problems are in fact harder, since
it doesn't have any restriction in recursion depth by nature.

Let me give you an example from my recent efforts:

For Stackless, I implemented pickling of frames and tracebacks,
besides many others. With the standard approach of pickling
them as they come, I would have got into recursion problems.
Although I got different advice of Armin Rigo ("do it right,
trash the pickler and build a stackless engine for it"), I didn't,
since I'm not trying to convince the stack-bound heads any longer.
I will do that for PyPy, when the time has come.

Keeping the current recursive pickling engine, I did this for
pickling of Tasklets, which are just small header objects
for frame chains:
Frames are pickled alone. They don't care about their f_back
field, therefore not introducing any recursive calls.
Tasklets are frame chains. They know which frames they
contain. And instead of causing recursions, tasklets simply
build a list of all the frames they need to be pickled,
and exactly that will happen, in an iterative manner.

Analogously it works with tracebacks, which also can show
very serious nesting. The problem with tracebacks is a bit
harder than with tasklets, since they don't have the
tasklet serving like a header. Therefore, I added a flag to
tracebacks, which marks the leading traceback object. That is,
this leading one will pickle all the other ones into a list,
again avoiding deep recursions. The trick was to modify
PyTraceBack_Here to tag the leading traceback object. Under the
(reasonable) assumption that this leading traceback object
will show up in your pickle, things work very smoothly.

If you want to know about how to pickle certain stuff, download
the Stackless CVS and have a look. There is support for pickling
tasklets, frames, code objects, iterators, tracebacks, and some
more to come. The most straight forward thing for you to look
into would probably be tracebackobject.c .

CVSROOT=:pserver:an*******@centera.de:/home/cvs
export CVSROOT
cvs co stackless

cheers - chris

--
Christian Tismer :^) <mailto:ti****@tismer.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 #1
2 2032
"Christian Tismer" <ti****@tismer.com> wrote ...
Mark Hahn wrote:
No thanks. I'd rather spend my time finding a tool that works or even
creating a new tool rather than working around a bad tool.
Sorry? What exactly is the bad tool you are referring to?


The bad tool is pickle. It cannot handle arbitrary graphs, which to me is a
bug.
I'm slightly unhappy with the time that I spent with
this message, in order to get *that* answer.

I didn't mean to be unappreciative of your help. Hopefully someone reading
this group will be helped by your message. I just don't want to try to work
around pickle's problems.
thanks for no further replies -- chris


I don't know what you mean by this.
Jul 18 '05 #2
Was your reply directing me to an example of how to write something that
works around the recursion limits of pickle, or was it something that could
be used directly to do pickling without the limits? I thought it was the
former.

In either case I apologize for my curt reply to your well thought out
answer. I didn't realize that I had pissed you off until I finally parsed
"thanks for no further replies -- chris" as "shut up" (which is kind of rude
by the way). One reason I had trouble parsing that is you asked me a
non-rhetorical question in the same post, which is a bit of a contradiction.

"Mark Hahn" <ma**@hahnca.com> wrote in message
news:vPVtb.6951$iS6.1812@fed1read04...
"Christian Tismer" <ti****@tismer.com> wrote ...
Mark Hahn wrote:
No thanks. I'd rather spend my time finding a tool that works or even
creating a new tool rather than working around a bad tool.
Sorry? What exactly is the bad tool you are referring to?


The bad tool is pickle. It cannot handle arbitrary graphs, which to me is

a bug.
I'm slightly unhappy with the time that I spent with
this message, in order to get *that* answer.

I didn't mean to be unappreciative of your help. Hopefully someone

reading this group will be helped by your message. I just don't want to try to work around pickle's problems.
thanks for no further replies -- chris


I don't know what you mean by this.

Jul 18 '05 #3

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

Similar topics

3
by: Paul Keating | last post by:
I have a very simple COM server written in Python that is trying to return a two-dimensional array 268 x 20. The values it contains are some small integers, some short (<29 character) Unicode...
1
by: Erik Brown | last post by:
sql = "CALL " + myschema + ".MYSPROC(?,?,?,?,?,?,?,?,?)"; rs = con.prepareCall(sql); rs.setString(1, user); rs.setString(2, action); rs.setString(3, versions); rs.setString(4, spec);...
6
by: Peter | last post by:
I have a C# program that checks directory on a UNIX server and once in a while I get the following error 'The network BIOS session limit was exceeded.' if I log off and log back on the error goes...
10
by: Vic Spainhower | last post by:
Hello, I have a php program that is building a grid (HTML table) from a MySQL database. The problems started when I added a dropdown menu to the grid and when I did the form buttons would not...
2
by: Boris Borcic | last post by:
Assuming that the items of my_stream share no content (they are dumps of db cursor fetches), is there a simple way to do the equivalent of def pickles(my_stream) : from cPickle import...
15
by: jane | last post by:
We are getting this error during a large large load. 2006-06-03-02.58.31.688266 Instance:sieinst Node:000 PID:1286274(db2agent (SRMW) 0) TID:1 Appid:GAFE423C.P4CE.0671B3070116 database...
3
by: Andrew Robinson | last post by:
My understanding is that strings and xml documents are limited to 2GB. Not that this is a good practice, but I have a client that wants to parse / convert (in memory) a document that is larger than...
2
by: Victor Lin | last post by:
Hi, I encounter a problem with pickle. I download a html from: ...
2
by: Tem | last post by:
Is there a way to set a hard limit on the capacity of a List<>?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.