Bug 1433905 - [mozprocess] Existence of _handle on Windows doesn't mean the process is still alive.
The assumption that when a handle is present for the process handler
on Windows doesn't mean that the process is still alive. It could
have already been externally killed, crashed, or closed itself.
Instead check the process exit code, and run clean-up steps if
the process is already gone.
MozReview-Commit-ID: 846ZAdsvGmq
--- a/testing/mozbase/mozprocess/mozprocess/processhandler.py
+++ b/testing/mozbase/mozprocess/mozprocess/processhandler.py
@@ -197,24 +197,40 @@ class ProcessHandlerMixin(object):
# a signal was explicitly set or not posix
send_sig(sig or signal.SIGKILL)
self.returncode = self.wait()
self._cleanup()
return self.returncode
def poll(self):
- """ Popen.poll
- Check if child process has terminated. Set and return returncode attribute.
+ """Check if child process has terminated, and set returncode attribute.
+
+ This method overrides the Popen.poll implementation for our custom
+ process handling for Windows.
"""
- # If we have a handle, the process is alive
- if isWin and getattr(self, '_handle', None):
- return None
+ if isWin:
+ if self._handle:
+ returncode = winprocess.GetExitCodeProcess(self._handle)
- return subprocess.Popen.poll(self)
+ # If the process doesn't exist anymore run cleanup steps
+ if returncode != winprocess.STILL_ACTIVE:
+ self.returncode = returncode
+ self._cleanup()
+ else:
+ self.returncode = None
+
+ else:
+ # Dude, the process is like totally dead!
+ return self.returncode
+
+ else:
+ self.returncode = subprocess.Popen.poll(self)
+
+ return self.returncode
def wait(self):
""" Popen.wait
Called to wait for a running process to shut down and return
its exit code
Returns the main process's exit code
"""
# This call will be different for each OS