diff --git a/subprocess2.py b/subprocess2.py index 785eb1909..34fdee828 100644 --- a/subprocess2.py +++ b/subprocess2.py @@ -44,10 +44,6 @@ VOID = object() # Error code when a process was killed because it timed out. TIMED_OUT = -2001 -# Globals. -# Set to True if you somehow need to disable this hack. -SUBPROCESS_CLEANUP_HACKED = False - class CalledProcessError(subprocess.CalledProcessError): """Augment the standard exception with more data.""" @@ -78,51 +74,11 @@ def kill_pid(pid): # Unable to import 'module' # pylint: disable=no-member,F0401 import signal - return os.kill(pid, signal.SIGKILL) - except ImportError: - pass - - -def kill_win(process): - """Kills a process with its windows handle. - - Has no effect on other platforms. - """ - try: - # Unable to import 'module' - # pylint: disable=import-error - import win32process - # Access to a protected member _handle of a client class - # pylint: disable=protected-access - return win32process.TerminateProcess(process._handle, -1) + return os.kill(pid, signal.SIGTERM) except ImportError: pass -def add_kill(): - """Adds kill() method to subprocess.Popen for python <2.6""" - if hasattr(subprocess.Popen, 'kill'): - return - - if sys.platform == 'win32': - subprocess.Popen.kill = kill_win - else: - subprocess.Popen.kill = lambda process: kill_pid(process.pid) - - -def hack_subprocess(): - """subprocess functions may throw exceptions when used in multiple threads. - - See http://bugs.python.org/issue1731717 for more information. - """ - global SUBPROCESS_CLEANUP_HACKED - if not SUBPROCESS_CLEANUP_HACKED and threading.activeCount() != 1: - # Only hack if there is ever multiple threads. - # There is no point to leak with only one thread. - subprocess._cleanup = lambda: None - SUBPROCESS_CLEANUP_HACKED = True - - def get_english_env(env): """Forces LANG and/or LANGUAGE to be English. @@ -208,10 +164,6 @@ class Popen(subprocess.Popen): popen_lock = threading.Lock() def __init__(self, args, **kwargs): - # Make sure we hack subprocess if necessary. - hack_subprocess() - add_kill() - env = get_english_env(kwargs.get('env')) if env: kwargs['env'] = env diff --git a/testing_support/gerrit_test_case.py b/testing_support/gerrit_test_case.py index 6cd060d59..45df909f0 100644 --- a/testing_support/gerrit_test_case.py +++ b/testing_support/gerrit_test_case.py @@ -352,9 +352,9 @@ class GerritTestCase(unittest.TestCase): return # If we get here, the gerrit process is still alive. Send the process - # SIGKILL for good measure. + # SIGTERM for good measure. try: - os.kill(gerrit_instance.gerrit_pid, signal.SIGKILL) + os.kill(gerrit_instance.gerrit_pid, signal.SIGTERM) except OSError: if e.errno == errno.ESRCH: # os.kill raised an error because the process doesn't exist. Maybe