issue #477: Popen.terminate() polyfill for Py2.4.

issue510
David Wilson 6 years ago
parent b7f39f26cd
commit 9f10695ee2

@ -10,6 +10,7 @@ import time
import mock import mock
import unittest2 import unittest2
import testlib import testlib
from testlib import Popen__terminate
import mitogen.parent import mitogen.parent
@ -269,7 +270,7 @@ class IterReadTest(testlib.TestCase):
if i > 3: if i > 3:
break break
finally: finally:
proc.terminate() Popen__terminate(proc)
proc.stdout.close() proc.stdout.close()
def test_deadline_exceeded_before_call(self): def test_deadline_exceeded_before_call(self):
@ -284,7 +285,7 @@ class IterReadTest(testlib.TestCase):
except mitogen.core.TimeoutError: except mitogen.core.TimeoutError:
self.assertEqual(len(got), 0) self.assertEqual(len(got), 0)
finally: finally:
proc.terminate() Popen__terminate(proc)
proc.stdout.close() proc.stdout.close()
def test_deadline_exceeded_during_call(self): def test_deadline_exceeded_during_call(self):
@ -306,7 +307,7 @@ class IterReadTest(testlib.TestCase):
self.assertLess(1, len(got)) self.assertLess(1, len(got))
self.assertLess(len(got), 20) self.assertLess(len(got), 20)
finally: finally:
proc.terminate() Popen__terminate(proc)
proc.stdout.close() proc.stdout.close()
@ -326,7 +327,7 @@ class WriteAllTest(testlib.TestCase):
try: try:
self.func(proc.stdin.fileno(), self.ten_ms_chunk) self.func(proc.stdin.fileno(), self.ten_ms_chunk)
finally: finally:
proc.terminate() Popen__terminate(proc)
proc.stdin.close() proc.stdin.close()
def test_deadline_exceeded_before_call(self): 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) lambda: self.func(proc.stdin.fileno(), self.ten_ms_chunk, 0)
)) ))
finally: finally:
proc.terminate() Popen__terminate(proc)
proc.stdin.close() proc.stdin.close()
def test_deadline_exceeded_during_call(self): def test_deadline_exceeded_during_call(self):
@ -349,7 +350,7 @@ class WriteAllTest(testlib.TestCase):
deadline) deadline)
)) ))
finally: finally:
proc.terminate() Popen__terminate(proc)
proc.stdin.close() proc.stdin.close()

@ -3,6 +3,7 @@ import logging
import os import os
import random import random
import re import re
import signal
import socket import socket
import subprocess import subprocess
import sys import sys
@ -77,9 +78,17 @@ def subprocess__check_output(*popenargs, **kwargs):
raise subprocess.CalledProcessError(retcode, cmd) raise subprocess.CalledProcessError(retcode, cmd)
return output return output
def Popen__terminate(proc):
os.kill(proc.pid, signal.SIGTERM)
if hasattr(subprocess, 'check_output'): if hasattr(subprocess, 'check_output'):
subprocess__check_output = subprocess.check_output subprocess__check_output = subprocess.check_output
if hasattr(subprocess.Popen, 'terminate'):
Popen__terminate = subprocess.Popen.terminate
def wait_for_port( def wait_for_port(
host, host,

Loading…
Cancel
Save