Home  >  Magazine  >  #73 May 2000  >  Python Programming for Beginners  >  Listing 5. Using Alarm Signal
Wednesday, March 29, 2000 | Last Updated 03:42:30 PM


  

Listing 5. Using Alarm Signal

#! /usr/local/bin/python
import signal
import sys
def alarm_handler(signal, frame):
    print 'BOOM!'
    sys.exit(0)
signal.signal(signal.SIGALRM, alarm_handler)
signal.alarm(5) # generate SIGALRM after 5 secs
n = 0
while 1:
    print n
    n = n+1