0

I'm currently using recursive BFS for a maze navigation algorithm that runs on a RaspberryPi, though I'm mostly doing testing and the majority of the work on Windows. Some of the recursion exceeds the recursion limit in python, so I increase sys.recursionlimit to a number I know for sure the recursion won't reach:

((mazeLength ** 2) + 10) 

for a buffer of 10. Typically, the mazeLength is far over 20, but this behavior can be observed at a mazeLength of 10.

Running a maze works fine on the windows machine, but the same maze and same code hits the recursion limit on the RaspberryPi. The issue can be solved on the Pi just by increasing the buffer to 50, but this solution definitely doesn't seem robust. Why could this be? Is it platform dependant, memory dependant, or some other issue entirely?

I know the obvious solution would be to switch to an iterative approach, but I don't want to change anything in its current form if possible.

Thanks in advance!

  • Without seeing the code one can only guess that more calls are necessary internally on Linux. You can try to set the limit very low on both OS and compare the resulting tracebacks. – Michael Butscher Apr 05 '22 at 00:51
  • The [docs](https://docs.python.org/3/library/sys.html#sys.setrecursionlimit) do mention that the max limit is platform-dependent and too high limit can lead to crashes. Check if any of these questions help - [How to know the maximum recursion depth one can set for a platform?](https://stackoverflow.com/questions/57363426/how-to-know-the-maximum-recursion-depth-one-can-set-for-a-platform-in-python-3) , [What is the hard recursion limit for Linux, Mac and Windows?](https://stackoverflow.com/questions/2917210/what-is-the-hard-recursion-limit-for-linux-mac-and-windows) – shriakhilc Apr 05 '22 at 00:57
  • When you execute a program, python has some stack already and this amount depends on the platform. This thread would be relevant. https://stackoverflow.com/questions/38265839/max-recursion-is-not-exactly-what-sys-getrecursionlimit-claims-how-come – Kota Mori Apr 05 '22 at 01:18
  • @shriakhilc, the program isn't reaching the limits of the OS since it still throws errors when recursion limits are set to smaller values with small mazes, and also because increasing the buffer solves it. – PolarisEmperor Apr 05 '22 at 02:27
  • @KotaMori thanks, this is likely the problem! I guess ill have to set the recursion limit based on how many are already on the stack. – PolarisEmperor Apr 05 '22 at 02:28
  • If you're actually doing BFS you shouldn't have to use recursion at all, so either your code is doing something that it shouldn't, or you're doing DFS? – MatsLindh Apr 05 '22 at 08:31

0 Answers0