Extending the recursion limit in GHPython?

Hi folks,

I’m running into a problem with a Python script that I’m currently working on, where after a couple of iterations, it exceeds the recursion limit somehow!?
By iterations, I mean that the component refreshes/recomputes, much like a Timer, and stores essential information, as a class object in the sticky dictionary.
Inside the class, I have a nested list, but instead of sublists, it contains dictionaries, and the error occurs here, when I try to check if a certain dictionary is included in this list.

Example:

test_dict = {"x": 0, "y": 2}
nest_list = [{"x": 0, "y": 0}, {"x": 0, "y": 1}, {"x": 0, "y": 2}, {"x": 1, "y": 0}, ...]

if test_dict in nested_list: # recursion error
    pass

In the script, I don’t do any kind of recursion myself, so I guess that it is used by the inclusion test?

I’ve tried raising the recursion limit, even setting the depth to hundreds of millions, but the error still occurs.

import sys

sys.setrecursionlimit(100000000)

Is this done differently in GHPython or possible at all?

I can’t currently show the script, since it’s work related and thus confidential. :confused:

Any ideas? Thanks.

It seems that IronPython basically has no limit set up on purpose:
https://mail.python.org/pipermail/ironpython-users/2007-October/005689.html
http://www.voidspace.org.uk/python/weblog/arch_d7_2007_09_29.shtml#e842

This means that it’s likely that .Net cannot just get to such a deep recursion limit on its own.

When I encountered this, it was always a bug. I never heard of a real, properly programmed case where this was happening. Of course, still, we can come up with some function that self-recurses enough to cause stack overflow.

By looking at the code sample, it looks like this will work fine:

test_dict = {"x": 0, "y": 2}
nest_list = [{"x": 0, "y": 0}, {"x": 0, "y": 1},  {"x": 1, "y": 0}] * 1000 + [{"x": 0, "y": 2}]

contains = False
if test_dict in nest_list: # no recursion error (?)
    contains = True
    
print(contains)

It’s hard to give suggestions without something to test. This test does not seem to exhibit the mentioned problem (tested in Rhino WIP).

2 Likes

Hello,

You’re not accidentally putting your object or list inside your list somewhere along the way are you?
Python allows recursive data structures, e.g.

>>> a = []
>>> a.append(a)
>>> a
[[...]]
>>> print a[0][0][0][0]
[[...]]
1 Like

OK, you guys probably won’t believe this, but after changing zip in the script and restarting my computer for a system update, the error has mysteriously disappeared for now. I’ve re-run the same script a couple of times and it still works. Weird right? I don’t get it!

Thanks for all your suggestions.

3 Likes

Just a small note, maybe also consider implementing your algorithm using a while/for loop (if possible):

Edit: I hadn’t properly understood the issue, but this might be useful none the less :nerd_face:

2 Likes