<s> """<STR_LIT>""" <EOL> import unittest <EOL> import thread <EOL> import signal <EOL> import os <EOL> import sys <EOL> from test . test_support import run_unittest , TestSkipped <EOL> if sys . platform [ : <NUM_LIT:3> ] in ( '<STR_LIT>' , '<STR_LIT>' ) or sys . platform == '<STR_LIT>' : <EOL> raise TestSkipped , "<STR_LIT>" % sys . platform <EOL> process_pid = os . getpid ( ) <EOL> signalled_all = thread . allocate_lock ( ) <EOL> def registerSignals ( ( for_usr1 , for_usr2 , for_alrm ) ) : <EOL> usr1 = signal . signal ( signal . SIGUSR1 , for_usr1 ) <EOL> usr2 = signal . signal ( signal . SIGUSR2 , for_usr2 ) <EOL> alrm = signal . signal ( signal . SIGALRM , for_alrm ) <EOL> return usr1 , usr2 , alrm <EOL> def handle_signals ( sig , frame ) : <EOL> signal_blackboard [ sig ] [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> signal_blackboard [ sig ] [ '<STR_LIT>' ] = thread . get_ident ( ) <EOL> def send_signals ( ) : <EOL> os . kill ( process_pid , signal . SIGUSR1 ) <EOL> os . kill ( process_pid , signal . SIGUSR2 ) <EOL> signalled_all . release ( ) <EOL> class ThreadSignals ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_signals ( self ) : <EOL> signalled_all . acquire ( ) <EOL> self . spawnSignallingThread ( ) <EOL> signalled_all . acquire ( ) <EOL> if signal_blackboard [ signal . SIGUSR1 ] [ '<STR_LIT>' ] == <NUM_LIT:0> or signal_blackboard [ signal . SIGUSR2 ] [ '<STR_LIT>' ] == <NUM_LIT:0> : <EOL> signal . alarm ( <NUM_LIT:1> ) <EOL> signal . pause ( ) <EOL> signal . alarm ( <NUM_LIT:0> ) <EOL> self . assertEqual ( signal_blackboard [ signal . SIGUSR1 ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( signal_blackboard [ signal . SIGUSR1 ] [ '<STR_LIT>' ] , <EOL> thread . get_ident ( ) ) <EOL> self . assertEqual ( signal_blackboard [ signal . SIGUSR2 ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( signal_blackboard [ signal . SIGUSR2 ] [ '<STR_LIT>' ] , <EOL> thread . get_ident ( ) ) <EOL> signalled_all . release ( ) <EOL> def spawnSignallingThread ( self ) : <EOL> thread . start_new_thread ( send_signals , ( ) ) <EOL> def test_main ( ) : <EOL> global signal_blackboard <EOL> signal_blackboard = { signal . SIGUSR1 : { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } , <EOL> signal . SIGUSR2 : { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } , <EOL> signal . SIGALRM : { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } } <EOL> oldsigs = registerSignals ( ( handle_signals , handle_signals , handle_signals ) ) <EOL> try : <EOL> run_unittest ( ThreadSignals ) <EOL> finally : <EOL> registerSignals ( oldsigs ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test_main ( ) </s>
