How to do infinite (or really deep) recursions in Stackless Python?What are the drawbacks of Stackless Python?Python: Maximum recursion depth exceededHow do I copy a file in Python?How can I safely create a nested directory?How can I remove a trailing newline in Python?How do I parse a string to a float or int in Python?How to get the current time in PythonHow can I make a time delay in Python?How do I get the number of elements in a list in Python?How do I concatenate two lists in Python?Stackless Python - Recursion in a for loop?How do I lowercase a string in Python?

Does the unit of measure matter when you are solving for the diameter of a circumference?

NIntegrate doesn't evaluate

Ticket to ride, 1910: What are the big cities

Why do Ryanair allow me to book connecting itineraries through a third party, but not through their own website?

What does the view outside my ship traveling at light speed look like?

How to use Palladio font in text body but Computer Modern for Equations?

Why do airplanes use an axial flow jet engine instead of a more compact centrifugal jet engine?

Is the Indo-European language family made up?

Plot twist where the antagonist wins

Website returning plaintext password

What is the largest (size) solid object ever dropped from an airplane to impact the ground in freefall?

A steel cutting sword?

My employer faked my resume to acquire projects

I unknowingly submitted plagarised work

Flying domestically in the US, is my State Issued ID all I need to get past security?

Is it rude to call a professor by their last name with no prefix in a non-academic setting?

Image processing: Removal of two spots in fundus images

Count Even Digits In Number

What is memelemum?

Is there a way to make it so the cursor is included when I prtscr key?

Why colon to denote that a value belongs to a type?

Wireless Multipoint Bridging / Backhaul Gateway Antenna and AP Selection

Why doesn't the Earth accelerate towards the Moon?

Where's this lookout in Nova Scotia?



How to do infinite (or really deep) recursions in Stackless Python?


What are the drawbacks of Stackless Python?Python: Maximum recursion depth exceededHow do I copy a file in Python?How can I safely create a nested directory?How can I remove a trailing newline in Python?How do I parse a string to a float or int in Python?How to get the current time in PythonHow can I make a time delay in Python?How do I get the number of elements in a list in Python?How do I concatenate two lists in Python?Stackless Python - Recursion in a for loop?How do I lowercase a string in Python?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








3















I know standard CPython has a limit on recursion depth, less than 1000 I think, so the below example code will fail with a "maximum recursion depth exceeded" error.



def rec_add(x):
if x == 0:
return x
else:
return x + add(x - 1)

print(rec_add(1000))


I heard Stackless Python supports infinite recursion depth, but if I run the above code with Stackless Python, it still reports a "maximum recursion depth exceeded" error. I think maybe I need to modify the code somehow to enable it to use the infinite recursion depth feature of Stackless Python?



Any idea how to do infinite recursions in Stackless Python? Thanks.



Note: I know how to increase standard CPython's recursion depth limit over 1000, and I know how to convert the above code to a simple iteration, or simply use the Gauss formula to calculate the sum, those are not what I'm looking for, and the above code is purely as an example.



EDIT: Like I already said in the "Note" part above (that I guess no one actually reads), I know how to increase CPython's recursion limit, and I know how to convert the example code into iterations or just a Gauss sum formula of n * (n + 1) / 2, I'm just asking here because I heard one of the great features of Stackless Python is that it enables infinite recursions, and I don't know how may I enable it for the example code.



EDIT2: I'm not sure if I got the idea of "Stackless Python supports infinite recursions" wrong, but here are some sources that says (or alludes to) that Stackless Python supports infinite recursions:



What are the drawbacks of Stackless Python?



https://bitbucket.org/stackless-dev/stackless/issues/96



https://stackless.readthedocs.io/en/3.6-slp/whatsnew/stackless.html










share|improve this question
























  • Possible duplicate of Python: Maximum recursion depth exceeded

    – Klaus D.
    Mar 24 at 6:04






  • 4





    Definitely not a duplicate, since I explicitly asked how to implement infinite recursions in Stackless Python, not how to increase the recursion depth limit over 1000 in standard CPython, which is what your linked question and its accepted answer there is about.

    – hellopeach
    Mar 24 at 6:07







  • 1





    I think you are operating under a fundamental misconception ... I see nothing related to infinite recursion in the stackless docs ... it seems it has more to do with async/await type stuff (which is now builtin to python)

    – Joran Beasley
    Mar 24 at 6:12







  • 2





    There is no infinite recursion.

    – Klaus D.
    Mar 24 at 6:14






  • 1





    I've seem from a past question that says Stackless support infinite recursion: stackoverflow.com/questions/588958/… , also some docs online talks about infinite recursions and how to limit the memory usage: stackless.readthedocs.io/en/3.6-slp/whatsnew/stackless.html

    – hellopeach
    Mar 24 at 6:19

















3















I know standard CPython has a limit on recursion depth, less than 1000 I think, so the below example code will fail with a "maximum recursion depth exceeded" error.



def rec_add(x):
if x == 0:
return x
else:
return x + add(x - 1)

print(rec_add(1000))


I heard Stackless Python supports infinite recursion depth, but if I run the above code with Stackless Python, it still reports a "maximum recursion depth exceeded" error. I think maybe I need to modify the code somehow to enable it to use the infinite recursion depth feature of Stackless Python?



Any idea how to do infinite recursions in Stackless Python? Thanks.



Note: I know how to increase standard CPython's recursion depth limit over 1000, and I know how to convert the above code to a simple iteration, or simply use the Gauss formula to calculate the sum, those are not what I'm looking for, and the above code is purely as an example.



EDIT: Like I already said in the "Note" part above (that I guess no one actually reads), I know how to increase CPython's recursion limit, and I know how to convert the example code into iterations or just a Gauss sum formula of n * (n + 1) / 2, I'm just asking here because I heard one of the great features of Stackless Python is that it enables infinite recursions, and I don't know how may I enable it for the example code.



EDIT2: I'm not sure if I got the idea of "Stackless Python supports infinite recursions" wrong, but here are some sources that says (or alludes to) that Stackless Python supports infinite recursions:



What are the drawbacks of Stackless Python?



https://bitbucket.org/stackless-dev/stackless/issues/96



https://stackless.readthedocs.io/en/3.6-slp/whatsnew/stackless.html










share|improve this question
























  • Possible duplicate of Python: Maximum recursion depth exceeded

    – Klaus D.
    Mar 24 at 6:04






  • 4





    Definitely not a duplicate, since I explicitly asked how to implement infinite recursions in Stackless Python, not how to increase the recursion depth limit over 1000 in standard CPython, which is what your linked question and its accepted answer there is about.

    – hellopeach
    Mar 24 at 6:07







  • 1





    I think you are operating under a fundamental misconception ... I see nothing related to infinite recursion in the stackless docs ... it seems it has more to do with async/await type stuff (which is now builtin to python)

    – Joran Beasley
    Mar 24 at 6:12







  • 2





    There is no infinite recursion.

    – Klaus D.
    Mar 24 at 6:14






  • 1





    I've seem from a past question that says Stackless support infinite recursion: stackoverflow.com/questions/588958/… , also some docs online talks about infinite recursions and how to limit the memory usage: stackless.readthedocs.io/en/3.6-slp/whatsnew/stackless.html

    – hellopeach
    Mar 24 at 6:19













3












3








3








I know standard CPython has a limit on recursion depth, less than 1000 I think, so the below example code will fail with a "maximum recursion depth exceeded" error.



def rec_add(x):
if x == 0:
return x
else:
return x + add(x - 1)

print(rec_add(1000))


I heard Stackless Python supports infinite recursion depth, but if I run the above code with Stackless Python, it still reports a "maximum recursion depth exceeded" error. I think maybe I need to modify the code somehow to enable it to use the infinite recursion depth feature of Stackless Python?



Any idea how to do infinite recursions in Stackless Python? Thanks.



Note: I know how to increase standard CPython's recursion depth limit over 1000, and I know how to convert the above code to a simple iteration, or simply use the Gauss formula to calculate the sum, those are not what I'm looking for, and the above code is purely as an example.



EDIT: Like I already said in the "Note" part above (that I guess no one actually reads), I know how to increase CPython's recursion limit, and I know how to convert the example code into iterations or just a Gauss sum formula of n * (n + 1) / 2, I'm just asking here because I heard one of the great features of Stackless Python is that it enables infinite recursions, and I don't know how may I enable it for the example code.



EDIT2: I'm not sure if I got the idea of "Stackless Python supports infinite recursions" wrong, but here are some sources that says (or alludes to) that Stackless Python supports infinite recursions:



What are the drawbacks of Stackless Python?



https://bitbucket.org/stackless-dev/stackless/issues/96



https://stackless.readthedocs.io/en/3.6-slp/whatsnew/stackless.html










share|improve this question
















I know standard CPython has a limit on recursion depth, less than 1000 I think, so the below example code will fail with a "maximum recursion depth exceeded" error.



def rec_add(x):
if x == 0:
return x
else:
return x + add(x - 1)

print(rec_add(1000))


I heard Stackless Python supports infinite recursion depth, but if I run the above code with Stackless Python, it still reports a "maximum recursion depth exceeded" error. I think maybe I need to modify the code somehow to enable it to use the infinite recursion depth feature of Stackless Python?



Any idea how to do infinite recursions in Stackless Python? Thanks.



Note: I know how to increase standard CPython's recursion depth limit over 1000, and I know how to convert the above code to a simple iteration, or simply use the Gauss formula to calculate the sum, those are not what I'm looking for, and the above code is purely as an example.



EDIT: Like I already said in the "Note" part above (that I guess no one actually reads), I know how to increase CPython's recursion limit, and I know how to convert the example code into iterations or just a Gauss sum formula of n * (n + 1) / 2, I'm just asking here because I heard one of the great features of Stackless Python is that it enables infinite recursions, and I don't know how may I enable it for the example code.



EDIT2: I'm not sure if I got the idea of "Stackless Python supports infinite recursions" wrong, but here are some sources that says (or alludes to) that Stackless Python supports infinite recursions:



What are the drawbacks of Stackless Python?



https://bitbucket.org/stackless-dev/stackless/issues/96



https://stackless.readthedocs.io/en/3.6-slp/whatsnew/stackless.html







python recursion python-stackless






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 6:37







hellopeach

















asked Mar 24 at 6:01









hellopeachhellopeach

1928




1928












  • Possible duplicate of Python: Maximum recursion depth exceeded

    – Klaus D.
    Mar 24 at 6:04






  • 4





    Definitely not a duplicate, since I explicitly asked how to implement infinite recursions in Stackless Python, not how to increase the recursion depth limit over 1000 in standard CPython, which is what your linked question and its accepted answer there is about.

    – hellopeach
    Mar 24 at 6:07







  • 1





    I think you are operating under a fundamental misconception ... I see nothing related to infinite recursion in the stackless docs ... it seems it has more to do with async/await type stuff (which is now builtin to python)

    – Joran Beasley
    Mar 24 at 6:12







  • 2





    There is no infinite recursion.

    – Klaus D.
    Mar 24 at 6:14






  • 1





    I've seem from a past question that says Stackless support infinite recursion: stackoverflow.com/questions/588958/… , also some docs online talks about infinite recursions and how to limit the memory usage: stackless.readthedocs.io/en/3.6-slp/whatsnew/stackless.html

    – hellopeach
    Mar 24 at 6:19

















  • Possible duplicate of Python: Maximum recursion depth exceeded

    – Klaus D.
    Mar 24 at 6:04






  • 4





    Definitely not a duplicate, since I explicitly asked how to implement infinite recursions in Stackless Python, not how to increase the recursion depth limit over 1000 in standard CPython, which is what your linked question and its accepted answer there is about.

    – hellopeach
    Mar 24 at 6:07







  • 1





    I think you are operating under a fundamental misconception ... I see nothing related to infinite recursion in the stackless docs ... it seems it has more to do with async/await type stuff (which is now builtin to python)

    – Joran Beasley
    Mar 24 at 6:12







  • 2





    There is no infinite recursion.

    – Klaus D.
    Mar 24 at 6:14






  • 1





    I've seem from a past question that says Stackless support infinite recursion: stackoverflow.com/questions/588958/… , also some docs online talks about infinite recursions and how to limit the memory usage: stackless.readthedocs.io/en/3.6-slp/whatsnew/stackless.html

    – hellopeach
    Mar 24 at 6:19
















Possible duplicate of Python: Maximum recursion depth exceeded

– Klaus D.
Mar 24 at 6:04





Possible duplicate of Python: Maximum recursion depth exceeded

– Klaus D.
Mar 24 at 6:04




4




4





Definitely not a duplicate, since I explicitly asked how to implement infinite recursions in Stackless Python, not how to increase the recursion depth limit over 1000 in standard CPython, which is what your linked question and its accepted answer there is about.

– hellopeach
Mar 24 at 6:07






Definitely not a duplicate, since I explicitly asked how to implement infinite recursions in Stackless Python, not how to increase the recursion depth limit over 1000 in standard CPython, which is what your linked question and its accepted answer there is about.

– hellopeach
Mar 24 at 6:07





1




1





I think you are operating under a fundamental misconception ... I see nothing related to infinite recursion in the stackless docs ... it seems it has more to do with async/await type stuff (which is now builtin to python)

– Joran Beasley
Mar 24 at 6:12






I think you are operating under a fundamental misconception ... I see nothing related to infinite recursion in the stackless docs ... it seems it has more to do with async/await type stuff (which is now builtin to python)

– Joran Beasley
Mar 24 at 6:12





2




2





There is no infinite recursion.

– Klaus D.
Mar 24 at 6:14





There is no infinite recursion.

– Klaus D.
Mar 24 at 6:14




1




1





I've seem from a past question that says Stackless support infinite recursion: stackoverflow.com/questions/588958/… , also some docs online talks about infinite recursions and how to limit the memory usage: stackless.readthedocs.io/en/3.6-slp/whatsnew/stackless.html

– hellopeach
Mar 24 at 6:19





I've seem from a past question that says Stackless support infinite recursion: stackoverflow.com/questions/588958/… , also some docs online talks about infinite recursions and how to limit the memory usage: stackless.readthedocs.io/en/3.6-slp/whatsnew/stackless.html

– hellopeach
Mar 24 at 6:19












1 Answer
1






active

oldest

votes


















1














After fumbling around I got the following code based on an official example code from more than a decade ago here



https://bitbucket.org/stackless-dev/stacklessexamples/src/a01959c240e2aeae068e56b86b4c2a84a8d854e0/examples/?at=default



so I modified the recursive addition code to look like this



import stackless


def call_wrapper(f, args, kwargs, result_ch):
result_ch.send(f(*args, **kwargs))


def call(f, *args, **kwargs):
result_ch = stackless.channel()
stackless.tasklet(call_wrapper)(f, args, kwargs, result_ch)
return result_ch.receive()


def rec_add(n):
if n <= 1:
return 1
return n + call(rec_add, n-1)


print(rec_add(1000000))


It works with large number like 1,000,000, I guess it is kind of an indirect recursion since the function calls another function which starts a tasklet that calls the function itself (or something like this).



Now I'm wondering if this is indeed the supposed way to implement an infinite recursion in Stackless Python, or are there more straight-forward/direct ways of doing it? Thanks.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321142%2fhow-to-do-infinite-or-really-deep-recursions-in-stackless-python%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    After fumbling around I got the following code based on an official example code from more than a decade ago here



    https://bitbucket.org/stackless-dev/stacklessexamples/src/a01959c240e2aeae068e56b86b4c2a84a8d854e0/examples/?at=default



    so I modified the recursive addition code to look like this



    import stackless


    def call_wrapper(f, args, kwargs, result_ch):
    result_ch.send(f(*args, **kwargs))


    def call(f, *args, **kwargs):
    result_ch = stackless.channel()
    stackless.tasklet(call_wrapper)(f, args, kwargs, result_ch)
    return result_ch.receive()


    def rec_add(n):
    if n <= 1:
    return 1
    return n + call(rec_add, n-1)


    print(rec_add(1000000))


    It works with large number like 1,000,000, I guess it is kind of an indirect recursion since the function calls another function which starts a tasklet that calls the function itself (or something like this).



    Now I'm wondering if this is indeed the supposed way to implement an infinite recursion in Stackless Python, or are there more straight-forward/direct ways of doing it? Thanks.






    share|improve this answer



























      1














      After fumbling around I got the following code based on an official example code from more than a decade ago here



      https://bitbucket.org/stackless-dev/stacklessexamples/src/a01959c240e2aeae068e56b86b4c2a84a8d854e0/examples/?at=default



      so I modified the recursive addition code to look like this



      import stackless


      def call_wrapper(f, args, kwargs, result_ch):
      result_ch.send(f(*args, **kwargs))


      def call(f, *args, **kwargs):
      result_ch = stackless.channel()
      stackless.tasklet(call_wrapper)(f, args, kwargs, result_ch)
      return result_ch.receive()


      def rec_add(n):
      if n <= 1:
      return 1
      return n + call(rec_add, n-1)


      print(rec_add(1000000))


      It works with large number like 1,000,000, I guess it is kind of an indirect recursion since the function calls another function which starts a tasklet that calls the function itself (or something like this).



      Now I'm wondering if this is indeed the supposed way to implement an infinite recursion in Stackless Python, or are there more straight-forward/direct ways of doing it? Thanks.






      share|improve this answer

























        1












        1








        1







        After fumbling around I got the following code based on an official example code from more than a decade ago here



        https://bitbucket.org/stackless-dev/stacklessexamples/src/a01959c240e2aeae068e56b86b4c2a84a8d854e0/examples/?at=default



        so I modified the recursive addition code to look like this



        import stackless


        def call_wrapper(f, args, kwargs, result_ch):
        result_ch.send(f(*args, **kwargs))


        def call(f, *args, **kwargs):
        result_ch = stackless.channel()
        stackless.tasklet(call_wrapper)(f, args, kwargs, result_ch)
        return result_ch.receive()


        def rec_add(n):
        if n <= 1:
        return 1
        return n + call(rec_add, n-1)


        print(rec_add(1000000))


        It works with large number like 1,000,000, I guess it is kind of an indirect recursion since the function calls another function which starts a tasklet that calls the function itself (or something like this).



        Now I'm wondering if this is indeed the supposed way to implement an infinite recursion in Stackless Python, or are there more straight-forward/direct ways of doing it? Thanks.






        share|improve this answer













        After fumbling around I got the following code based on an official example code from more than a decade ago here



        https://bitbucket.org/stackless-dev/stacklessexamples/src/a01959c240e2aeae068e56b86b4c2a84a8d854e0/examples/?at=default



        so I modified the recursive addition code to look like this



        import stackless


        def call_wrapper(f, args, kwargs, result_ch):
        result_ch.send(f(*args, **kwargs))


        def call(f, *args, **kwargs):
        result_ch = stackless.channel()
        stackless.tasklet(call_wrapper)(f, args, kwargs, result_ch)
        return result_ch.receive()


        def rec_add(n):
        if n <= 1:
        return 1
        return n + call(rec_add, n-1)


        print(rec_add(1000000))


        It works with large number like 1,000,000, I guess it is kind of an indirect recursion since the function calls another function which starts a tasklet that calls the function itself (or something like this).



        Now I'm wondering if this is indeed the supposed way to implement an infinite recursion in Stackless Python, or are there more straight-forward/direct ways of doing it? Thanks.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 6:56









        hellopeachhellopeach

        1928




        1928





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321142%2fhow-to-do-infinite-or-really-deep-recursions-in-stackless-python%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript