omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    sys.settecursionlimit won't change from the default value of 256

    Pythonista
    2
    6
    3385
    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.
    • Wizardofozzie
      Wizardofozzie last edited by

      I'm getting an Exception RECURSION ERROR which is due to the default value being 256; ie sys.getrecursionlimit() = 256

      The only way to remedy this is by prepending sys.settecursionlimit(512) so the line of code reads sys.settecursionlimit(512); foo()

      Normally the sys.settecursionlimit function will change the default value (ie on windows), but in the console, it'll return the default 256 on the next line for sys.getrecursionlimit()

      How can I work around this issue?

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

        I am able to replicate. This only happens in the Pythonista console, NOT in Pythonista programs. The workaround is:

        def my_workaround():
            sys.setrecursionlimit(512)
            foo()
            print(sys.getrecursionlimit())
        
        my_workaround()
        

        The behavior that you are seeing is an artifact of the Pythonista console which needs to compensate for the fact that Apple only allows iOS apps to have a single thread of execution. When you are not feeding a constant set of commands into the console, it seems to reset some of its values including recursion limit. By defining a function (or a series of ;-separated commands), you keep the console from doing that reset until after your function returns.

        To see the behavior clearly, check out:

        import sys
        
        def recursion_gsg(x):
            print(sys.getrecursionlimit())
            sys.setrecursionlimit(x)
            print(sys.getrecursionlimit())
            
        def recursion_test():
            orig = sys.getrecursionlimit()
            print('=' * 10)
            recursion_gsg(350)
            recursion_gsg(512)
            recursion_gsg(1024)
            recursion_gsg(orig)
            
        recursion_test()
        

        If you type that line-by-line into the Pythonista console then you get the expected output:

        ==========
        300
        350
        350
        512
        512
        1024
        1024
        300
        

        However, if you now type in each line of recursion_test() into the console as a unique command, you get:

        ==========
        300
        350
        300
        512
        300
        1024
        300
        300
        
        1 Reply Last reply Reply Quote 0
        • Wizardofozzie
          Wizardofozzie last edited by

          FANTASTIC answer!

          First off, your default is 300? I'm on iPad Air iOS 8.3. Why is mine 256?

          I'll need time to digest this, but I'll play around with it now:)

          1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by

            I think mine is 300 because I am running the current beta version of Pythonista.

            1 Reply Last reply Reply Quote 0
            • Wizardofozzie
              Wizardofozzie last edited by

              Beta? Huh! Any idea when the release is going to be? Just curious

              1 Reply Last reply Reply Quote 0
              • ccc
                ccc last edited by

                Nope. When it is ready and not before I hope.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors