@@ -826,26 +826,20 @@ def test_specific_shell(self):
826826 def _kill_process (self , method , * args ):
827827 # Do not inherit file handles from the parent.
828828 # It should fix failures on some platforms.
829- p = subprocess .Popen ([sys .executable , "-c" , "input()" ], close_fds = True ,
830- stdin = subprocess .PIPE , stderr = subprocess .PIPE )
831-
832- # Let the process initialize (Issue #3137)
833- time .sleep (0.4 )
834- # The process should not terminate prematurely
835- self .assertIsNone (p .poll ())
836- # Retry if the process do not receive the signal.
837- count , maxcount = 0 , 10
838- while count < maxcount and p .poll () is None :
839- getattr (p , method )(* args )
840- time .sleep (0.1 )
841- count += 1
842-
843- if count == maxcount :
844- self .skipTest ("apparently failed to send the signal" )
845- self .assertIsNotNone (p .poll (), "the subprocess did not terminate" )
846- if count > 1 :
847- print ("p.{}{} succeeded after "
848- "{} attempts" .format (method , args , count ), file = sys .stderr )
829+ p = subprocess .Popen ([sys .executable , "-c" , """if 1:
830+ import sys, time
831+ sys.stdout.write('x\\ n')
832+ sys.stdout.flush()
833+ time.sleep(30)
834+ """ ],
835+ close_fds = True ,
836+ stdin = subprocess .PIPE ,
837+ stdout = subprocess .PIPE ,
838+ stderr = subprocess .PIPE )
839+ # Wait for the interpreter to be completely initialized before
840+ # sending any signal.
841+ p .stdout .read (1 )
842+ getattr (p , method )(* args )
849843 return p
850844
851845 def test_send_signal (self ):
0 commit comments