From 111c06a7ca61ad965ae3905080f2172cc139c562 Mon Sep 17 00:00:00 2001 From: Henrik Skupin Date: Mon, 12 Feb 2018 22:46:14 +0100 Subject: [PATCH] Bug 892902 - [mozprocess] Returncode for kill() on Windows has to be set from wait(). r=ahal Currently the returncode gets set immediately after the process has been terminated via TerminateJobObject() or TerminateProcess(). Given that in both cases the process has not been quit yet, but still waits for all streams to be closed, the returncode has to be set by via wait(). Also in case of TerminateJobObject() the _cleanup method is never called if an exception occurs. MozReview-Commit-ID: 4NEyqafN0DD --HG-- extra : rebase_source : ae176d5e052785cc77865e1bf220013e87d7a3f0 --- .../mozprocess/mozprocess/processhandler.py | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/testing/mozbase/mozprocess/mozprocess/processhandler.py b/testing/mozbase/mozprocess/mozprocess/processhandler.py index 9c2ca87559a5..3efb650b7721 100644 --- a/testing/mozbase/mozprocess/mozprocess/processhandler.py +++ b/testing/mozbase/mozprocess/mozprocess/processhandler.py @@ -139,20 +139,19 @@ class ProcessHandlerMixin(object): def kill(self, sig=None): if isWin: - if not self._ignore_children and self._handle and self._job: - self.debug("calling TerminateJobObject") - winprocess.TerminateJobObject(self._job, winprocess.ERROR_CONTROL_C_EXIT) - self.returncode = winprocess.GetExitCodeProcess(self._handle) - elif self._handle: - self.debug("calling TerminateProcess") - try: + try: + if not self._ignore_children and self._handle and self._job: + self.debug("calling TerminateJobObject") + winprocess.TerminateJobObject(self._job, winprocess.ERROR_CONTROL_C_EXIT) + elif self._handle: + self.debug("calling TerminateProcess") winprocess.TerminateProcess(self._handle, winprocess.ERROR_CONTROL_C_EXIT) - except Exception: - traceback.print_exc() - raise OSError("Could not terminate process") - finally: - winprocess.GetExitCodeProcess(self._handle) - self._cleanup() + except WindowsError: + self._cleanup() + + traceback.print_exc() + raise OSError("Could not terminate process") + else: def send_sig(sig, retries=0): pid = self.detached_pid or self.pid