I would like to boot into a python app. My python app has the excellent pigpiod daemon as a prerequisite. I am using Busybox init process. I have a pigpiod launch script /etc/init.d/SXpigpiod and my python application launch script /etc/init.d/SYmyapp (X is smaller than Y).
The problem I encounter is this - pigpiod immediately forks thus init moves on swiftly, however it takes some time before pigpiod is actually responsive. If myapp is called by init too soon, it's game over because python pigpio module cannot connect to pigpiod. I know it is a simple race condition because if I run /etc/init.d/SYmyapp from console everything is fine. Also, making X as small as possible and Y as large as possible, thus ensuring that several other init tasks are executed in between (notably S40network), resolves the problem. This is not good enough though, I need to minimise cold boot time and most of the other init tasks will disappear eventually. I have tried looping inside myapp init script waiting for pigpiod to start responding, like this:
while [ "$(pigs pigpv 2>&1 >/dev/null)" = 'socket connect failed' ] do #echo "pigpiod down" sleep 0.1 done
This appears to block pigpiod from ever loading. Implementing a similar thing inside python app also appears to block pigpiod from loading:
while not pigpio.pi().connected: time.sleep(0.1)
Is there a way to ensure that myapp is started as soon as pigpiod is responding, without blocking pigpiod initilaisation?