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 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()

@ -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,

Loading…
Cancel
Save