@@ -21,25 +21,19 @@ def sigusr1_handler(self, signum, frame):
21
21
self .got_signals ['SIGUSR1' ] += 1
22
22
raise SIGUSR1Exception
23
23
24
- def wait_signal (self , child , signame , exc_class = None ):
25
- try :
26
- if child is not None :
27
- # This wait should be interrupted by exc_class
28
- # (if set)
29
- child .wait ()
30
-
31
- timeout = 10.0
32
- deadline = time .monotonic () + timeout
33
-
34
- while time .monotonic () < deadline :
35
- if self .got_signals [signame ]:
36
- return
37
- signal .pause ()
38
- except BaseException as exc :
39
- if exc_class is not None and isinstance (exc , exc_class ):
40
- # got the expected exception
24
+ def wait_signal (self , child , signame ):
25
+ if child is not None :
26
+ # This wait should be interrupted by exc_class
27
+ # (if set)
28
+ child .wait ()
29
+
30
+ timeout = 10.0
31
+ deadline = time .monotonic () + timeout
32
+
33
+ while time .monotonic () < deadline :
34
+ if self .got_signals [signame ]:
41
35
return
42
- raise
36
+ signal . pause ()
43
37
44
38
self .fail ('signal %s not received after %s seconds'
45
39
% (signame , timeout ))
@@ -65,8 +59,9 @@ def test_interprocess_signal(self):
65
59
self .assertEqual (self .got_signals , {'SIGHUP' : 1 , 'SIGUSR1' : 0 ,
66
60
'SIGALRM' : 0 })
67
61
68
- with self .subprocess_send_signal (pid , "SIGUSR1" ) as child :
69
- self .wait_signal (child , 'SIGUSR1' , SIGUSR1Exception )
62
+ with self .assertRaises (SIGUSR1Exception ):
63
+ with self .subprocess_send_signal (pid , "SIGUSR1" ) as child :
64
+ self .wait_signal (child , 'SIGUSR1' )
70
65
self .assertEqual (self .got_signals , {'SIGHUP' : 1 , 'SIGUSR1' : 1 ,
71
66
'SIGALRM' : 0 })
72
67
@@ -75,8 +70,9 @@ def test_interprocess_signal(self):
75
70
child .wait ()
76
71
77
72
try :
78
- signal .alarm (1 )
79
- self .wait_signal (None , 'SIGALRM' , KeyboardInterrupt )
73
+ with self .assertRaises (KeyboardInterrupt ):
74
+ signal .alarm (1 )
75
+ self .wait_signal (None , 'SIGALRM' )
80
76
self .assertEqual (self .got_signals , {'SIGHUP' : 1 , 'SIGUSR1' : 1 ,
81
77
'SIGALRM' : 0 })
82
78
finally :
0 commit comments