I am trying to gather data from a camera and a sensor using one loop for each and python Threading. The problem is that when I run each loop independently they work, but at the same time using threading only one of the two works and if one crashes, then the other starts working. I am using the powermode MODE30ALL and the exact same code works fine on a classic computer.
The python threading module does not release the GIL (global interpreter lock) so even if multiple OS threads are launched, only one is scheduled to execute at a time (the idea is to context shift with sleep(), spending most of your time waiting on external things). To actually do more than one thing at once in parallel, you must use the multiprocessing module which launches multiple instances of the python interpreter or write a c extension (or use Cython to do so) which releases the gil, does stuff in parallel, and re-acquires it (not doing so segfaults). Rule of thumb: the threading module (or async) is for stuff that’s IO bound while multiprocessing is for stuff that’s CPU bound.