Pydsdl "maximum recursion depth exceeded" error

Hi, I have two cyphal message definitions in my cyphal_test root namespace. In the first message, I have a single fixed size array and in the second message, I have a message1 and precisely 107 boolean fields like this:
Message1.0.1.dsdl

uint8[8] id
@sealed

Message2.0.1.dsdl

Message1.0.1 m1
bool bool1
...
bool bool107

When I compile and read the extent field on the second message, I get the “maximum recursion depth exceeded” error when my system recursion limit is less than 970.

>>> import sys
>>> sys.setrecursionlimit(970)
>>> types = pydsdl.read_namespace('cyphal_test/')
>>> types[1].extent
  File "pydsdl/_bit_length_set/_symbolic.py", line 143, in max
    return sum(x.max for x in self._children)
  File "pydsdl/_bit_length_set/_symbolic.py", line 143, in <genexpr>
    return sum(x.max for x in self._children)
  File "pydsdl/_bit_length_set/_symbolic.py", line 296, in max
    self._max = self._child.max
  File "pydsdl/_bit_length_set/_symbolic.py", line 104, in max
    return self._pad(self._child.max)
  File "pydsdl/_bit_length_set/_symbolic.py", line 296, in max
    self._max = self._child.max
  File "pydsdl/_bit_length_set/_symbolic.py", line 143, in max
    return sum(x.max for x in self._children)
  File "pydsdl/_bit_length_set/_symbolic.py", line 143, in <genexpr>
    return sum(x.max for x in self._children)
  File "pydsdl/_bit_length_set/_symbolic.py", line 296, in max
    self._max = self._child.max
  File "pydsdl/_bit_length_set/_symbolic.py", line 104, in max
    return self._pad(self._child.max)
  File "pydsdl/_bit_length_set/_symbolic.py", line 296, in max
    self._max = self._child.max
  File "pydsdl/_bit_length_set/_symbolic.py", line 104, in max
    return self._pad(self._child.max)
  File "/pydsdl/_bit_length_set/_symbolic.py", line 296, in max
    self._max = self._child.max
RecursionError: maximum recursion depth exceeded

Is this a bug or is pydsdl truly doing so many recursive operations?

1 Like

You must be doing something exceedingly unorthodox!

This is not a bug. PyDSDL uses very deep call stacks that grow linearly with the number of attributes in a data type definition. If you really must have 107 attributes in a data type definition (instead of, say, using an array like bool[107]), you will need to enlarge the Python stack.