#NEWLINE# def RegisterSignalHandler( signal_num , handler , is_final_handler = False ) : #NEWLINE# #INDENT# 'Registers a handler for signal signal_num.\n\n  Unlike calling signal.signal():\n    - This function can be called from any thread (and will cause the handler to\n      be run by the main thread when the signal is received).\n    - Handlers are cumulative: When a given signal is received, all registered\n      handlers will be executed (with the exception that only the last handler\n      to register with is_final_handler=True will be called).\n\n  Handlers should make no ordering assumptions, other than that the last handler\n  to register with is_final_handler=True will be called after all the other\n  handlers.\n\n  Args:\n    signal_num: The signal number with which to associate handler.\n    handler: The handler.\n    is_final_handler: Bool indicator whether handler should be called last among\n                      all the handlers for this signal_num. The last handler to\n                      register this way survives; other handlers registered with\n                      is_final_handler=True will not be called when the signal\n                      is received.\n  Raises:\n    RuntimeError: if attempt is made to register a signal_num not in\n        GetCaughtSignals.\n  ' #NEWLINE# if ( signal_num not in GetCaughtSignals ( ) ) : #NEWLINE# #INDENT# raise RuntimeError ( ( 'Attempt to register handler (%s) for signal %d, which is not in GetCaughtSignals' % ( handler , signal_num ) ) ) #NEWLINE# #UNINDENT# if is_final_handler : #NEWLINE# #INDENT# _final_signal_handlers [ signal_num ] = handler #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# _non_final_signal_handlers [ signal_num ] . append ( signal_num )