diff options
author | Robert Guo <robertguo@me.com> | 2016-08-01 18:20:13 -0400 |
---|---|---|
committer | Robert Guo <robertguo@me.com> | 2016-08-16 10:52:20 -0400 |
commit | b13bac6c1bbd11a1cf8015e3fd77b686cec1d290 (patch) | |
tree | b0e0e41ebc7a6c53b6a205cda4beb4605f7f97ac /buildscripts/resmokelib/core | |
parent | f5c94de1eeaa2da2c66749dc80558228ae6ad314 (diff) | |
download | mongo-b13bac6c1bbd11a1cf8015e3fd77b686cec1d290.tar.gz |
SERVER-25358 resmoke should shutdown mongod cleanly on Windows
Diffstat (limited to 'buildscripts/resmokelib/core')
-rw-r--r-- | buildscripts/resmokelib/core/process.py | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/buildscripts/resmokelib/core/process.py b/buildscripts/resmokelib/core/process.py index f54b0f0a640..b8efa8af25a 100644 --- a/buildscripts/resmokelib/core/process.py +++ b/buildscripts/resmokelib/core/process.py @@ -56,6 +56,7 @@ _POPEN_LOCK = threading.Lock() if sys.platform == "win32": import win32api import win32con + import win32event import win32job import win32process import winerror @@ -163,11 +164,40 @@ class Process(object): raise def stop(self): - """ - Terminates the process. - """ - + """Terminate the process.""" if sys.platform == "win32": + + # Attempt to cleanly shutdown mongod. + if len(self.args) > 0 and self.args[0].find("mongod") != -1: + mongo_signal_handle = None + try: + mongo_signal_handle = win32event.OpenEvent( + win32event.EVENT_MODIFY_STATE, False, "Global\\Mongo_" + + str(self._process.pid)) + + if not mongo_signal_handle: + # The process has already died. + return + win32event.SetEvent(mongo_signal_handle) + # Wait 60 seconds for the program to exit. + status = win32event.WaitForSingleObject( + self._process._handle, 60 * 1000) + if status == win32event.WAIT_OBJECT_0: + return + except win32process.error as err: + # ERROR_FILE_NOT_FOUND (winerror=2) + # ERROR_ACCESS_DENIED (winerror=5) + # ERROR_INVALID_HANDLE (winerror=6) + # One of the above errors is received if the process has + # already died. + if err[0] not in (2, 5, 6): + raise + finally: + win32api.CloseHandle(mongo_signal_handle) + + print "Failed to cleanly exit the program, calling TerminateProcess() on PID: " +\ + str(self._process.pid) + # Adapted from implementation of Popen.terminate() in subprocess.py of Python 2.7 # because earlier versions do not catch exceptions. try: |