Below is the code to run a function when keyboard interruption occurs.
import signal
print("press ctrl+c for interruption") 
def xyz():
    print("im xyz")
  
def keyboardInterruptHandler(signal, frame):
    xyz()
    #print("call your function here".format(signal))
    exit(0)
signal.signal(signal.SIGINT, keyboardInterruptHandler)
while True:
    pass
Hope this helps!!
If you need to learn more about Python, It's recommended to join Python Online Training today.
Thanks!