Catch signal in Python

In Python, you can use the signal module to capture the Ctrl+C signal. Below is an example code:

import signal

def signal_handler(signal, frame):
    print("Ctrl+C signal captured!")

signal.signal(signal.SIGINT, signal_handler)
signal.pause()
Leave a message