<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Thank you,</div><div><br></div><div>I'll do nothing in my code for the moment (working on a prototype). By the time i get closer to production i'll do some calculation and set recursion limit accordingly. </div><div><br></div><div>Do you know by chance whether it is possible to change the python recursionlimit dynamically (mid-run)? I could then catch the exception, log the exception, double the limit, call pickle again ( for now).</div><div><br></div><div>Cheers, lars<br><br><div>====================================</div><div>Lars van Gemerden</div><div><a href="mailto:lars@rational-it.com">lars@rational-it.com</a></div><div>+31 6 26 88 55 39</div><div>====================================</div></div><div><br>On 3 okt. 2012, at 15:25, Kristján Valur Jónsson <<a href="mailto:kristjan@ccpgames.com">kristjan@ccpgames.com</a>> wrote:<br><br></div><blockquote type="cite"><div>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1203902389;
        mso-list-type:hybrid;
        mso-list-template-ids:-1453543812 134807569 134807577 134807579 134807567 134807577 134807579 134807567 134807577 134807579;}
@list l0:level1
        {mso-level-text:"%1\)";
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->


<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Hello Lars.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">First off, deep recursion isn’t really a problem if you are using a single thread, since most operating systems will just allocate more stack as you need it.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">In the unlikely situation that you get into OS problems, though, this is when Stackless will help more than regular python will.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><span style="mso-list:Ignore">1)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><!--[endif]--><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">for pickle, just make sure that your sys.setrecursionlimit() is high enough.  for cPickle you don’t need any such thing.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><span style="mso-list:Ignore">2)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><!--[endif]--><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Nothing mitigates pytyon’s recursionlimit.  Stackless’ stack spilling is a behind-the-scenes way of trimming the c stack, that is all.  But python’s
 recursionlimit only applies to regular python code.  C code is unarffercted by it and cPickle is c code.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><span style="mso-list:Ignore">3)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><!--[endif]--><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">python 2 and 3 are the same, except that in 3, “pickle” is implemented in C and “_pickle” is a pure python reference implementation.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><span style="mso-list:Ignore">4)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><!--[endif]--><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Nothing special, it is the same as using the regular (non-C) pickle module.  Make sure that sys.setrecursionlimit() is set high.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">So, to be clear:  sys.*recursionlimit is really an artificial construct in python, there to help avoid infinite recursion.  Normally, you just increase it to
 help with your deep recursion, the OS then allocates stack space.  Stackless is the same, but it will try to use less OS stack space.  This will help on “threads” (that have fixed stacks, normally) and on systems that run out of c stack easily.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">K<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> <a href="mailto:stackless-bounces@stackless.com">stackless-bounces@stackless.com</a> [<a href="mailto:stackless-bounces@stackless.com">mailto:stackless-bounces@stackless.com</a>]
<b>On Behalf Of </b>lars van Gemerden<br>
<b>Sent:</b> 3. október 2012 11:44<br>
<b>To:</b> The Stackless Python Mailing List<br>
<b>Subject:</b> Re: [Stackless] Pickling and recursion<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Hi Kristjan,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks for your response, it is somewhat clearer now. However I have some more questions about the subject (because some of my data structures are very recursive and redesigning them would be a lot of work):<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">- under what conditions can stackless mitigate these recursion limits (for pickle and cPickle, what do i need to avoid)?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">- does this mitigation circumvent pythons recursion limit or does it only kick in after the python recursion limit has been disabled?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">- i am working on stackless python 2.7, what are the differences with stackless python 3 in this respect?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">- What happens if i write my own highly recursive persistence module (i wrote one that converts most python objects to XML via the etree module)? <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">This is far from the only reason I use stackless, but it would be a great bonus if i could be reasonable sure that i won't run into recursion problems in the near future (this has been one of those nagging uncertainties in the back of my
 mind).<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Cheers, Lars<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Tue, Oct 2, 2012 at 11:34 AM, Kristján Valur Jónsson <<a href="mailto:kristjan@ccpgames.com" target="_blank">kristjan@ccpgames.com</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal">Not necessarily.<br>
the term "stackless" is historic in this respect.  Originally, the attempt was made to have pure python code work independently of the C stack.<br>
In practice, this change was simply too big to be maintainable and so, nowadays, stackless does try to do this when possible, but otherwise relents.<br>
Pickling in version 3 of python is by default done using C code, and C code normally also uses the c stack for recursion.<br>
<br>
Two opposite caveats exists:<br>
1) Stackless does attempt to mitigate C recursion by using "stack spilling" where very deep c invocation stacks are stored away on the heap.  This process is not foolproof and can become degenerated, but it is designed to work with regular python function invocation
 and pickling.<br>
2) Python imposes its own recursion limit.  This has to be disabled to go very deep.  But again, this does not apply to c pickling.<br>
<br>
So no, stackless python does not promise stackless python evaluation in the literal sense, but it might help you for very deep pickling.  Since it is not the primary purpose of Stackless, your mileage may vary.<br>
K<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><br>
> -----Original Message-----<br>
> From: <a href="mailto:stackless-bounces@stackless.com">stackless-bounces@stackless.com</a> [mailto:<a href="mailto:stackless-">stackless-</a><br>
> <a href="mailto:bounces@stackless.com">bounces@stackless.com</a>] On Behalf Of Lars van Gemerden<br>
> Sent: 1. október 2012 08:16<br>
> To: <a href="mailto:stackless@stackless.com">stackless@stackless.com</a><br>
> Subject: [Stackless] Pickling and recursion<br>
><br>
> Hello,<br>
><br>
> I was wandering whether using stackless also means that there is (practically)<br>
> no limit to the recursion depth of highly recursive objects when using<br>
> pickle/cPickle?<br>
><br>
> Cheers, Lars<br>
><br>
> ====================================<br>
> Lars van Gemerden<br>
> <a href="mailto:lars@rational-it.com">lars@rational-it.com</a><br>
> <a href="tel:%2B31%206%2026%2088%2055%2039">+31 6 26 88 55 39</a><br>
> ====================================<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">> _______________________________________________<br>
> Stackless mailing list<br>
> <a href="mailto:Stackless@stackless.com">Stackless@stackless.com</a><br>
> <a href="http://www.stackless.com/mailman/listinfo/stackless" target="_blank">http://www.stackless.com/mailman/listinfo/stackless</a><br>
<br>
<br>
<br>
_______________________________________________<br>
Stackless mailing list<br>
<a href="mailto:Stackless@stackless.com">Stackless@stackless.com</a><br>
<a href="http://www.stackless.com/mailman/listinfo/stackless" target="_blank">http://www.stackless.com/mailman/listinfo/stackless</a><o:p></o:p></p>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">-- <br>
====================================<br>
Lars van Gemerden<br>
<a href="mailto:lars@rational-it.com">lars@rational-it.com</a><br>
+31 6 26 88 55 39<br>
====================================<o:p></o:p></p>
</div>
</div>
</div>


</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Stackless mailing list</span><br><span><a href="mailto:Stackless@stackless.com">Stackless@stackless.com</a></span><br><span><a href="http://www.stackless.com/mailman/listinfo/stackless">http://www.stackless.com/mailman/listinfo/stackless</a></span></div></blockquote></body></html>