Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    RuntimeError: maximum recursion depth exceeded?

    Scheduled Pinned Locked Moved MicroPython
    runtime errorrecursion
    4 Posts 2 Posters 1.7k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      semireg
      last edited by semireg

      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'

      1 Reply Last reply Reply Quote 0
      • J Offline
        johand
        last edited by

        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

        S 1 Reply Last reply Reply Quote 0
        • S Offline
          semireg @johand
          last edited by

          @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?

          1 Reply Last reply Reply Quote 0
          • S Offline
            semireg
            last edited by

            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?

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • 1 / 1
            • First post
              Last post

            Pycom on Twitter

            Pycom