New submission from David Schere <dsch...@arinc.com>:

When doing an exit() within a signal handler for an alarm I am seeing something 
strange:


This code works, it exits within signal handler as expected. You never see the 
print statement executed.
import signal
import time
import sys
import traceback

def handler( *args ):
   sys.exit(-1) #<-- terminate program


signal.signal( signal.SIGALRM, handler ) 
# set alarm to go off in one second that calls handler()
signal.alarm( 1 )


time.sleep( 3 )


print 'You should never see this message'


This code results in sys.exit() begin ignored and the code inside the “except:” 
block being executed!

import signal
import time
import sys
import traceback

def handler( *args ):
   sys.exit(-1) #<-- terminate program


signal.signal( signal.SIGALRM, handler ) 
# set alarm to go off in one second that calls handler()
signal.alarm( 1 )

try:
   time.sleep( 3 )
except:
   print 'This message should not be seen'
   sys.exit()
   
print 'You should never see this message'


The work around is to raise an exception inside the 
handler() function.

----------
messages: 100120
nosy: david_schere
severity: normal
status: open
title: sys.exit() doesn't execute inside a signal handler while blocked inside 
an try/except
type: behavior
versions: Python 2.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8021>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to