diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-20 01:33:21 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-20 01:33:21 (GMT) |
commit | 3d8580f690d13817af941afe4958576e8d7922af (patch) | |
tree | b1090750a59e849d59ab406e5f9ab7b9bb7d7af1 /Lib | |
parent | 84e751a4429637418970eebc6300d8ac0603da8a (diff) | |
download | cpython-3d8580f690d13817af941afe4958576e8d7922af.zip cpython-3d8580f690d13817af941afe4958576e8d7922af.tar.gz cpython-3d8580f690d13817af941afe4958576e8d7922af.tar.bz2 |
Try a more robust implementation of _kill_process
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_subprocess.py | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index dc6eff6..61d7ce9 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -826,26 +826,20 @@ class POSIXProcessTestCase(BaseTestCase): def _kill_process(self, method, *args): # Do not inherit file handles from the parent. # It should fix failures on some platforms. - p = subprocess.Popen([sys.executable, "-c", "input()"], close_fds=True, - stdin=subprocess.PIPE, stderr=subprocess.PIPE) - - # Let the process initialize (Issue #3137) - time.sleep(0.4) - # The process should not terminate prematurely - self.assertIsNone(p.poll()) - # Retry if the process do not receive the signal. - count, maxcount = 0, 10 - while count < maxcount and p.poll() is None: - getattr(p, method)(*args) - time.sleep(0.1) - count += 1 - - 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) + p = subprocess.Popen([sys.executable, "-c", """if 1: + import sys, time + sys.stdout.write('x\\n') + sys.stdout.flush() + time.sleep(30) + """], + close_fds=True, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + # Wait for the interpreter to be completely initialized before + # sending any signal. + p.stdout.read(1) + getattr(p, method)(*args) return p def test_send_signal(self): |