From 9f10695ee2c612f4c7e7f271c147566aed72bf1d Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 23 Jan 2019 12:44:08 +0000 Subject: [PATCH] issue #477: Popen.terminate() polyfill for Py2.4. --- tests/parent_test.py | 13 +++++++------ tests/testlib.py | 9 +++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/parent_test.py b/tests/parent_test.py index d0e198bb..325ca8fc 100644 --- a/tests/parent_test.py +++ b/tests/parent_test.py @@ -10,6 +10,7 @@ import time import mock import unittest2 import testlib +from testlib import Popen__terminate import mitogen.parent @@ -269,7 +270,7 @@ class IterReadTest(testlib.TestCase): if i > 3: break finally: - proc.terminate() + Popen__terminate(proc) proc.stdout.close() def test_deadline_exceeded_before_call(self): @@ -284,7 +285,7 @@ class IterReadTest(testlib.TestCase): except mitogen.core.TimeoutError: self.assertEqual(len(got), 0) finally: - proc.terminate() + Popen__terminate(proc) proc.stdout.close() def test_deadline_exceeded_during_call(self): @@ -306,7 +307,7 @@ class IterReadTest(testlib.TestCase): self.assertLess(1, len(got)) self.assertLess(len(got), 20) finally: - proc.terminate() + Popen__terminate(proc) proc.stdout.close() @@ -326,7 +327,7 @@ class WriteAllTest(testlib.TestCase): try: self.func(proc.stdin.fileno(), self.ten_ms_chunk) finally: - proc.terminate() + Popen__terminate(proc) proc.stdin.close() def test_deadline_exceeded_before_call(self): @@ -336,7 +337,7 @@ class WriteAllTest(testlib.TestCase): lambda: self.func(proc.stdin.fileno(), self.ten_ms_chunk, 0) )) finally: - proc.terminate() + Popen__terminate(proc) proc.stdin.close() def test_deadline_exceeded_during_call(self): @@ -349,7 +350,7 @@ class WriteAllTest(testlib.TestCase): deadline) )) finally: - proc.terminate() + Popen__terminate(proc) proc.stdin.close() diff --git a/tests/testlib.py b/tests/testlib.py index 197b59e0..ef401a78 100644 --- a/tests/testlib.py +++ b/tests/testlib.py @@ -3,6 +3,7 @@ import logging import os import random import re +import signal import socket import subprocess import sys @@ -77,9 +78,17 @@ def subprocess__check_output(*popenargs, **kwargs): raise subprocess.CalledProcessError(retcode, cmd) return output + +def Popen__terminate(proc): + os.kill(proc.pid, signal.SIGTERM) + + if hasattr(subprocess, 'check_output'): subprocess__check_output = subprocess.check_output +if hasattr(subprocess.Popen, 'terminate'): + Popen__terminate = subprocess.Popen.terminate + def wait_for_port( host,