Is it possible to interrupt a try-except code in python with gpio interrupt to generate exception? In the "try" part i'm openning a socket and use socket.serve_forever(). I want to make a hard-reboot to the program, using a reboot button that is connected to a gpio. What I want is that when button is pressed-an interrupt/exception is invoked and it goes right to the "except" part (going out of an infinite loop) , closing the socket and restart the program (later openning the socket again).
Example for code:
try:
... #code
socket.serve_forever
except GPIO INTERRUPT:
print "button was pressed, closing socket and restart program..."
socket.close()
restart()