Defining our own signal handler : signal « Buildin Module « Python Tutorial






import time
import signal

def stop( signalNumber, frame ):
   global keepRunning
   keepRunning -= 1
   print "Ctrl-C pressed; keepRunning is", keepRunning

keepRunning = 3

signal.signal( signal.SIGINT, stop )

while keepRunning:
   print "Executing..."
   time.sleep( 1 )








14.12.signal
14.12.1.Defining our own signal handler