Bug 892902 - [mozprocess] Returncode for kill() on Windows has to be set from wait().
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
--- a/testing/mozbase/mozprocess/mozprocess/processhandler.py
+++ b/testing/mozbase/mozprocess/mozprocess/processhandler.py
@@ -134,30 +134,29 @@ class ProcessHandlerMixin(object):
self.poll(_deadstate=sys.maxint)
if handle or self._job or self._io_port:
self._cleanup()
else:
subprocess.Popen.__del__(self)
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
if not self._ignore_children:
try:
os.killpg(pid, sig)
except BaseException as e:
# On Mac OSX if the process group contains zombie