Stop SIGALRM when function returns
问题 I have a problem that I can't seem to solve by myself. I'm writing a small python script and I would like to know why my signal.alarm still works after the function it's located in returned. Here is the code: class AlarmException(Exception): pass def alarmHandler(signum, frame): raise AlarmException def startGame(): import signal signal.signal(signal.SIGALRM, alarmHandler) signal.alarm(5) try: # some code... return 1 except AlarmException: # some code... return -1 def main(): printHeader()