Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1277

Python • Multiple threads collapsing in Python with Raspberry Pi 4

$
0
0
I'm having problems trying to finish a college project working with Raspberry Pi 4B.

The project is in Python and consists of 5 threads, where 2 of them run Machine Learning predictions, and a 3rd one runs a series of calculations in orden to reach the same output as the one the Machine Learning model predicts (that way I can contrast whether the output is a reasonable value or not). The other two threads are: one waits 10 secs and activates a flag (flag needed to start the processing) and the other one prints the values (both predicted from the ML models and from the calculations) on the terminal.

My problem is that, when I try to run all threads at the same time, the ML models run correctly but my calculations threads doesn't do anything. Instead, if I don't start the ML threads, the calculations thread works fine.

I think that the Raspberry doesn't have enough computing capacity and therefor the calculations thread collapses.

It is not necessary that all 3 threads are running at the same time (I want to be able to choose whether I want to see the ML predictions printed on the terminal or the calculations output), so I have tried disabling the threads when I don't use them (using thread.join() ) and starting them again when I decide I want that thread to start running again (thread.start() ) but it's not working correctly.

I have also tried having two flags (ML_flag and calculations_flag) that are needed to run the prediction or calculation functions, but also hasn't worked.

Any ideas on other techniques that I can use so that the ML predictions and calculations run separately and don't collapse?

Thanks!

Statistics: Posted by aag97 — Fri Apr 19, 2024 11:39 am



Viewing all articles
Browse latest Browse all 1277

Trending Articles