@Alejandro7c suggested to, just in case, have a look to a RTOS to achieve a faster and better resources management on the RaspberryPi.