@@ -4103,16 +4103,17 @@ class FastWaitTestCase(BaseTestCase):
41034103 """
41044104 CAN_USE_PIDFD_OPEN = subprocess ._CAN_USE_PIDFD_OPEN
41054105 CAN_USE_KQUEUE = subprocess ._CAN_USE_KQUEUE
4106+ COMMAND = [sys .executable , "-c" , "import time; time.sleep(0.3)" ]
4107+ WAIT_TIMEOUT = 0.0001 # 0.1 ms
41064108
41074109 def assert_fast_waitpid_error (self , patch_point ):
41084110 # Emulate a case where pidfd_open() or kqueue() fails.
41094111 # Busy-poll wait should be used as fallback.
41104112 exc = OSError (errno .EMFILE , os .strerror (errno .EMFILE ))
41114113 with mock .patch (patch_point , side_effect = exc ) as m :
4112- p = subprocess .Popen ([sys .executable ,
4113- "-c" , "import time; time.sleep(0.3)" ])
4114+ p = subprocess .Popen (self .COMMAND )
41144115 with self .assertRaises (subprocess .TimeoutExpired ):
4115- p .wait (timeout = 0.0001 )
4116+ p .wait (self . WAIT_TIMEOUT )
41164117 self .assertEqual (p .wait (timeout = support .SHORT_TIMEOUT ), 0 )
41174118 self .assertTrue (m .called )
41184119
@@ -4128,8 +4129,7 @@ def test_wait_kqueue_error(self):
41284129 def test_kqueue_control_error (self ):
41294130 # Emulate a case where kqueue.control() fails. Busy-poll wait
41304131 # should be used as fallback.
4131- p = subprocess .Popen ([sys .executable ,
4132- "-c" , "import time; time.sleep(0.3)" ])
4132+ p = subprocess .Popen (self .COMMAND )
41334133 kq_mock = mock .Mock ()
41344134 kq_mock .control .side_effect = OSError (
41354135 errno .EPERM , os .strerror (errno .EPERM )
@@ -4138,16 +4138,15 @@ def test_kqueue_control_error(self):
41384138
41394139 with mock .patch ("select.kqueue" , return_value = kq_mock ) as m :
41404140 with self .assertRaises (subprocess .TimeoutExpired ):
4141- p .wait (timeout = 0.0001 )
4141+ p .wait (self . WAIT_TIMEOUT )
41424142 self .assertEqual (p .wait (timeout = support .SHORT_TIMEOUT ), 0 )
41434143 self .assertTrue (m .called )
41444144
41454145 def assert_wait_race_condition (self , patch_target , real_func ):
41464146 # Call pidfd_open() / kqueue(), then terminate the process.
41474147 # Make sure that the wait call (poll() / kqueue.control())
41484148 # still works for a terminated PID.
4149- p = subprocess .Popen ([sys .executable ,
4150- "-c" , "import time; time.sleep(0.3)" ])
4149+ p = subprocess .Popen (self .COMMAND )
41514150
41524151 def wrapper (* args , ** kwargs ):
41534152 ret = real_func (* args , ** kwargs )
@@ -4185,10 +4184,9 @@ def waitpid_wrapper(pid, flags):
41854184 real_waitpid = os .waitpid
41864185 with mock .patch .object (subprocess .Popen , patch_target , return_value = True ) as m1 :
41874186 with mock .patch ("os.waitpid" , side_effect = waitpid_wrapper ) as m2 :
4188- p = subprocess .Popen ([sys .executable ,
4189- "-c" , "import time; time.sleep(0.3)" ])
4187+ p = subprocess .Popen (self .COMMAND )
41904188 with self .assertRaises (subprocess .TimeoutExpired ):
4191- p .wait (timeout = 0.0001 )
4189+ p .wait (self . WAIT_TIMEOUT )
41924190 self .assertEqual (p .wait (timeout = support .SHORT_TIMEOUT ), 0 )
41934191 assert m1 .called
41944192 assert m2 .called
@@ -4209,10 +4207,9 @@ def test_fast_path_avoid_busy_loop(self):
42094207 # assert that the busy loop is not called as long as the fast
42104208 # wait is available
42114209 with mock .patch ('time.sleep' ) as m :
4212- p = subprocess .Popen ([sys .executable ,
4213- "-c" , "import time; time.sleep(0.3)" ])
4210+ p = subprocess .Popen (self .COMMAND )
42144211 with self .assertRaises (subprocess .TimeoutExpired ):
4215- p .wait (timeout = 0.0001 )
4212+ p .wait (self . WAIT_TIMEOUT )
42164213 self .assertEqual (p .wait (timeout = support .LONG_TIMEOUT ), 0 )
42174214 assert not m .called
42184215
0 commit comments