<s> from signal import signal , SIG_IGN , SIG_DFL <EOL> from twisted . internet import reactor <EOL> from datetime import datetime <EOL> from traceback import print_exc <EOL> from sys import stdout <EOL> class Signal ( object ) : <EOL> callback = None <EOL> parameters = None <EOL> previous_handler = None <EOL> def __init__ ( self , signum , callback , * parameters ) : <EOL> self . callback = callback <EOL> self . parameters = parameters <EOL> self . previous_handler = signal ( signum , self . signal_handler ) <EOL> def signal_handler ( self , signum , * frame ) : <EOL> try : <EOL> reactor . callFromThread ( self . callback , * self . parameters ) <EOL> except : <EOL> print datetime . now ( ) , '<STR_LIT>' <EOL> print '<STR_LIT:->' * <NUM_LIT> <EOL> print_exc ( file = stdout ) <EOL> print '<STR_LIT:->' * <NUM_LIT> <EOL> stdout . flush ( ) <EOL> if self . previous_handler not in ( SIG_IGN , SIG_DFL ) : <EOL> try : <EOL> self . previous_handler ( signum , * frame ) <EOL> except : <EOL> print datetime . now ( ) , '<STR_LIT>' <EOL> print '<STR_LIT:->' * <NUM_LIT> <EOL> print_exc ( file = stdout ) <EOL> print '<STR_LIT:->' * <NUM_LIT> <EOL> stdout . flush ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from signal import SIGHUP <EOL> from os import kill , getpid <EOL> def test ( arguments ) : <EOL> arguments [ '<STR_LIT:test>' ] = True <EOL> reactor . crash ( ) <EOL> arguments = { '<STR_LIT:test>' : False } <EOL> Signal ( SIGHUP , test , arguments ) <EOL> kill ( getpid ( ) , SIGHUP ) <EOL> reactor . run ( ) <EOL> assert ( arguments [ '<STR_LIT:test>' ] ) </s>
