0

I am attempting to have a program load on boot and have successfully achieved my desired function by modifying the /etc/rc.local file and adding the following line -

(sleep 15; python /home/pi/Desktop/DatabaseController.py) &

This is the majority of the DatabaseController.py file, I believe the loop_start is a blocking function -

def main():
    clientName = "DatabaseController"
    serverAddress = "10.116.10.191"

     mqttClient = mqtt.Client(clientName)

     mqttClient.on_connect = connectionStatus
     mqttClient.on_message = messageDecoder

     mqttClient.connect(serverAddress)

     mqttClient.loop_start()

main()

while True:
   print("Waiting...")
   time.sleep(.25)

My problem is that when I try to SSH into the Raspberry Pi to perform other functions it tells me Operation Timed Out. However, when I manually execute the line to run the code I am still able to SSH into the Raspberry Pi. How can I regain this ability? I've also tried using cron, but it did not work either.

  • For a start I would replace the while loop with signal.pause(). That should keep your script alive. The MQTT bit runs in a different thread and will keep going – Dirk Aug 11 '18 at 20:01
  • Does signal.pause() cause the script to wait until the a signal is received? If so, will I need to import or assign signal? – HobarGJ Aug 11 '18 at 20:39
  • Yes. You need to import signal docs.python.org/2/library/signal.html#signal.pause – Dirk Aug 11 '18 at 23:08
1

It seems this line is somehow disturbing your boot process. As the command is started in the background, it should not block execution. Some parts of the boot process have trouble if there are still references to the open files. You can try to start it with

(sleep 15; python /home/pi/Desktop/DatabaseController.py < /dev/null &> /dev/null &) 
  • Thank you for the assistance, this instantly solved my problem! – HobarGJ Aug 11 '18 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.