@@ -498,8 +498,7 @@ def test_block_unlock(self):
498498 signum = signal .SIGUSR1
499499
500500 def handler (signum , frame ):
501- handler .tripped = True
502- handler .tripped = False
501+ 1 / 0
503502
504503 def read_sigmask ():
505504 return signal .pthread_sigmask (signal .SIG_BLOCK , [])
@@ -519,36 +518,39 @@ def read_sigmask():
519518 # function.
520519 faulthandler .cancel_dump_tracebacks_later ()
521520
521+ # Install our signal handler
522522 old_handler = signal .signal (signum , handler )
523523 self .addCleanup (signal .signal , signum , old_handler )
524524
525- # unblock SIGUSR1, copy the old mask and test our signal handler
525+ # Unblock SIGUSR1 (and copy the old mask) to test our signal handler
526526 old_mask = signal .pthread_sigmask (signal .SIG_UNBLOCK , [signum ])
527527 self .addCleanup (signal .pthread_sigmask , signal .SIG_SETMASK , old_mask )
528- os . kill ( pid , signum )
529- self . assertTrue ( handler . tripped )
528+ with self . assertRaises ( ZeroDivisionError ):
529+ os . kill ( pid , signum )
530530
531- # block SIGUSR1
532- handler . tripped = False
531+ # Block and then raise SIGUSR1. The signal is blocked: the signal
532+ # handler is not called, and the signal is now pending
533533 signal .pthread_sigmask (signal .SIG_BLOCK , [signum ])
534534 os .kill (pid , signum )
535- self .assertFalse (handler .tripped )
536535
537- # check the mask
536+ # Check the new mask
538537 blocked = read_sigmask ()
539538 self .assertIn (signum , blocked )
540539 self .assertEqual (set (old_mask ) ^ set (blocked ), {signum })
541540
542- # unblock SIGUSR1
543- signal .pthread_sigmask (signal .SIG_UNBLOCK , [signum ])
544- os .kill (pid , signum )
545- self .assertTrue (handler .tripped )
541+ # Unblock SIGUSR1
542+ with self .assertRaises (ZeroDivisionError ):
543+ # unblock the pending signal calls immediatly the signal handler
544+ signal .pthread_sigmask (signal .SIG_UNBLOCK , [signum ])
545+ with self .assertRaises (ZeroDivisionError ):
546+ os .kill (pid , signum )
546547
547- # check the mask
548+ # Check the new mask
548549 unblocked = read_sigmask ()
549550 self .assertNotIn (signum , unblocked )
550551 self .assertEqual (set (blocked ) ^ set (unblocked ), {signum })
551552 self .assertSequenceEqual (old_mask , unblocked )
553+ # Finally, restore the previous signal handler and the signal mask
552554
553555
554556def test_main ():
0 commit comments