Micropython RuntimeError: maximum recursion depth exceeded
Closed this issue · 0 comments
Hi There,
When I run the SX126 code in the primary thread it works great and I can happily communicate between two Lora modules while testing functionality.
So that I can keep my user interface responsive in the main thread, I'm trying to run the SX126 code as a second thread on the other Pico processor core.
Now when a message comes in from the remote device I receive the following error.
Traceback (most recent call last):
File "sx1262.py", line 275, in _onIRQ
File "subprocess.py", line 73, in cb
File "sx1262.py", line 187, in recv
File "sx1262.py", line 251, in _readData
File "sx126x.py", line 483, in startReceive
File "sx126x.py", line 540, in startReceiveCommon
File "sx126x.py", line 1133, in setPacketParams
File "sx126x.py", line 1228, in fixInvertedIQ
File "sx126x.py", line 1034, in writeRegister
File "sx126x.py", line 1274, in SPIwriteCommand
File "sx126x.py", line 1291, in SPItransfer
RuntimeError: maximum recursion depth exceeded
There is no recursion in my code, I think the problem is the number function calls is filling up the thread's stack space which is smaller on the second thread than on the main thread.
I don't see this as a bug really but more of a limitation.
I have posted a question here however the problem is very specific to this SX126X software so I'm not expecting a big response.
https://github.com/orgs/micropython/discussions/10614
I have played with _thread.stack_size() but I can't get it to make any difference at all.
Do you know of other users attempted to run this code in thread2?
Any ideas what I could do to work around the problem?
My Hardware is
MicroPython v1.19.1-746-gf2de289ef on 2022-12-13; Raspberry Pi Pico W with RP2040
Waveshare Pico LoRa-SX126X
Thanks in advance for any information.
David
UPDATE
After some suggestions on another post I found if I add the following line immediately before the call to the sub process it works.
I only needed to add 1kb to the default stack size for thread 2 which is 4kb.
_thread.stack_size(5*1024) # Default stack size for thread two is only 4k
_thread.start_new_thread(subprocess.subMain,())
Hope this helps someone else.
Feel free to delete this if it just muddies the water.
Thanks
David