Try a more robust implementation of _kill_process
This commit is contained in:
parent
84e751a442
commit
3d8580f690
|
@ -826,26 +826,20 @@ class POSIXProcessTestCase(BaseTestCase):
|
||||||
def _kill_process(self, method, *args):
|
def _kill_process(self, method, *args):
|
||||||
# Do not inherit file handles from the parent.
|
# Do not inherit file handles from the parent.
|
||||||
# It should fix failures on some platforms.
|
# It should fix failures on some platforms.
|
||||||
p = subprocess.Popen([sys.executable, "-c", "input()"], close_fds=True,
|
p = subprocess.Popen([sys.executable, "-c", """if 1:
|
||||||
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
|
import sys, time
|
||||||
|
sys.stdout.write('x\\n')
|
||||||
# Let the process initialize (Issue #3137)
|
sys.stdout.flush()
|
||||||
time.sleep(0.4)
|
time.sleep(30)
|
||||||
# The process should not terminate prematurely
|
"""],
|
||||||
self.assertIsNone(p.poll())
|
close_fds=True,
|
||||||
# Retry if the process do not receive the signal.
|
stdin=subprocess.PIPE,
|
||||||
count, maxcount = 0, 10
|
stdout=subprocess.PIPE,
|
||||||
while count < maxcount and p.poll() is None:
|
stderr=subprocess.PIPE)
|
||||||
getattr(p, method)(*args)
|
# Wait for the interpreter to be completely initialized before
|
||||||
time.sleep(0.1)
|
# sending any signal.
|
||||||
count += 1
|
p.stdout.read(1)
|
||||||
|
getattr(p, method)(*args)
|
||||||
if count == maxcount:
|
|
||||||
self.skipTest("apparently failed to send the signal")
|
|
||||||
self.assertIsNotNone(p.poll(), "the subprocess did not terminate")
|
|
||||||
if count > 1:
|
|
||||||
print("p.{}{} succeeded after "
|
|
||||||
"{} attempts".format(method, args, count), file=sys.stderr)
|
|
||||||
return p
|
return p
|
||||||
|
|
||||||
def test_send_signal(self):
|
def test_send_signal(self):
|
||||||
|
|
Loading…
Reference in New Issue