RuntimeError: maximum recursion depth exceeded?



  • I ran into an issue that doesn't look like the error I'm seeing. The traceback from the error has 19 calls. There is no recursion.

    I did this to duplicate real infinite recursion:

    >>> def foo():
    ...     blah()
    ...
    >>>
    >>> def blah():
    ...     foo()
    ...
    >>> foo()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 2, in foo
      File "<stdin>", line 2, in blah
      File "<stdin>", line 2, in foo
      File "<stdin>", line 2, in blah
      File "<stdin>", line 2, in foo
      File "<stdin>", line 2, in blah
      File "<stdin>", line 2, in foo
      File "<stdin>", line 2, in blah
      File "<stdin>", line 2, in foo
      File "<stdin>", line 2, in blah
      File "<stdin>", line 2, in foo
      File "<stdin>", line 2, in blah
      File "<stdin>", line 2, in foo
      File "<stdin>", line 2, in blah
      File "<stdin>", line 2, in foo
      File "<stdin>", line 2, in blah
      File "<stdin>", line 2, in foo
      File "<stdin>", line 2, in blah
      File "<stdin>", line 2, in foo
      File "<stdin>", line 2, in blah
      File "<stdin>", line 2, in foo
      File "<stdin>", line 2, in blah
    RuntimeError: maximum recursion depth exceeded
    

    Is there a way to easily expand this limitation?

    References that aren't quite what I'm facing:
    • https://github.com/micropython/micropython/issues/1050
    • https://forum.micropython.org/viewtopic.php?t=2922

    And of course, sys.setrecursionlimit(50) yields AttributeError: 'module' object has no attribute 'setrecursionlimit'



  • Quick update. In esp32/mptask.h there exists:

    #define MICROPY_TASK_PRIORITY                   MP_THREAD_PRIORITY
    #define MICROPY_TASK_STACK_SIZE                 (8 * 1024)
    #define MICROPY_TASK_STACK_SIZE_PSRAM           (12 * 1024)
    #define MICROPY_TASK_STACK_LEN                  (MICROPY_TASK_STACK_SIZE / sizeof(StackType_t))
    

    I believe this is where we could increase the stack size, but I am unsure of the sanity and practicality of this...

    Thoughts?



  • @johand Sorry for not being clearer in my original post. Forget the code I posted because that was just a different way to show the same error I was seeing in my real codebase. I didn't want to go through the trouble of sanitizing the text in the real call stack - so I wrote something that just called each other and that elicited the same error "maximum recursion depth exceeded."

    My question is simply: Assuming the maximum recursion depth is hard-coded somewhere... where is it, and how can I increase it slightly?



  • When you call a function there is a reference to the calling code (to know where to continue when the called function ends), so in this case you get a list (stack) with unlimited number of references.

    Why don´t you do something like this?

    while True:
        foo()
    

    Johan


Log in to reply
 

Pycom on Twitter