Balena Containers and Threads on RPI CM4

Hi

I have a complete python program running and working correctly on RPI4 CM using IO Board. The program establishes a connection with an AMQP Broker and receives messages from the broker to control several peripherals and send back to the broker messages with different sensor values. The program uses 3 threads: Main, AMQP_Consumer and AMQP_Producer and the data between the Threads uses queues and all necessary resource management such as semaphores. Once again everything works correctly in rpi and the problems start when I try to integrate the program with Balena.

I have been evaluating Balena as a fleet management system to see if it meets our customers’ needs, as we aim to produce up to 100 devices this year and more next year. However, although I was able to configure everything correctly, it seems that the container running the python program doesn’t handle threads very well. The device logs in the Balena Dashboard show that the program is able to establish the AMQP connection to the broker, start the AMQP_Consumer and AMQP_Producer threads, but then it stops working correctly and it appears that the device is only able to run the AMQP_Consumer thread since he receives messages from the broker and not do any work in the Main and AMQP_Producer threads.

Are there any known issues with Balena OS and containers related to the handling of Threads?

Best regards.

Hello @embedded first of all welcome to the balena community!

There is no known issue between balena containers and Threads.

Could you please share more details of the errors that you see?

Thanks!

Well

Related to this issue, I managed to fix it.

It looks like the problem was related to the gpiod package. Since balenaOS does not allow the program to run the gpiod package, the program crashed and only one of the threads was able to function correctly.

I just removed the part of the code that was using the gpiod package and the program is now able to run all three threads simultaneously.

Now I have to find a way to control the gpio.

1 Like