Skip to content
Advertisement

reboot raspberry if python script stop with error

I use a Python script on a raspberry that communicates with the Internet and USB with an Arduino and it happens that one of the 2 communications blow because of some error, and I would like in case this file python stops because of an error that the Raspberry restarts ! can some one hepl me ?

Advertisement

Answer

This is a solution to restart the Pi. You will have to check for your error first. That can be done using a try/except construction:

import os
try:
    <<your code here>>
except:
    os.system("sudo reboot") # reboots the pi
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement