def stop(self): """Stops a running mongod """ if not self.proc: self.logger.error("Probable bug: self.proc already" \ " unset in stop()") raise Exception("Failed to stop mongod") return try: if os.sys.platform.startswith("win"): import win32job win32job.TerminateJobObject(self.job_object, -1) import time # Windows doesn't seem to kill the process immediately, so give # it some time to die time.sleep(5) else: # This actually works # mongo_executable = os.path.abspath(os.path.join(self.mongod, '..', 'mongo')) # argv = [mongo_executable, "--port", self.port, "--eval", "db.getSiblingDB('admin').shutdownServer()"] # proc = subprocess.Popen(argv) # This function not available in Python 2.5 self.proc.terminate() except AttributeError: from os import kill kill(self.proc.pid, 15) except Exception, e: self.logger.error("Error shutting down mongod - {0}".format(e)) sys.exit(1)
def stop(self, timeout=TIMEOUTS['WaitForProcessStop'], hard=False): """Stop a process running. On Windows this is always a hard termination. """ try: with self.__lock: if self.exitStatus is not None: return try: if self.__job: win32job.TerminateJobObject(self.__job, 0) else: win32process.TerminateProcess(self.__hProcess, 0) # pragma: no cover except Exception as e: # pragma: no cover # ignore errors unless the process is still running if win32process.GetExitCodeProcess( self.hProcess) == win32con.STILL_ACTIVE: log.warning( 'Failed to terminate job object for process %s: %s' % (self, e)) # try this approach instead win32process.TerminateProcess(self.__hProcess, 0) self.wait(timeout=timeout) except Exception as ex: # pragma: no cover raise ProcessError("Error stopping process: %s" % ex)
def kill(self): self.__p.kill() if self.__user_job_object_flag: try: win32job.TerminateJobObject(self.hJob, 1) except Exception as e: pass self.timeout_flag = True
def kill_job(self): if self.job is None: return log.warning("Kill win32 JobObject handle: {0}".format(self.job)) try: win32job.TerminateJobObject(self.job, 1) except pywintypes.error as err: log.warning("Could not terminate job object") log.warning(err)
def kill_job(self): ''' kill_job is for windows only''' if not WIN: return log.info("Kill Windows JobObject handle: {0}".format(self.job)) try: win32job.TerminateJobObject(self.job, 1) except pywintypes.error as err: log.warning("Could not terminate job object") log.warning(err) return err
def stop(self): try: if os.sys.platform == "win32": import win32job win32job.TerminateJobObject(self.subprocess_job_object, -1) # Windows doesn't seem to kill the process immediately, so give # it some time to die time.sleep(5) elif hasattr(self.subprocess, "terminate"): # This method added in Python 2.6 self.subprocess.terminate() else: os.kill(self.subprocess.pid, 15) except Exception as e: print >> self.subprocess_outputs.stderr, "error shutting down process" print >> self.subprocess_outputs.stderr, e return self.wait()
def stop(self): if not self.proc: print >> sys.stderr, "probable bug: self.proc unset in stop()" return try: if os.sys.platform == "win32": import win32job win32job.TerminateJobObject(self.job_object, -1) import time # Windows doesn't seem to kill the process immediately, so give it some time to die time.sleep(5) else: # This function not available in Python 2.5 self.proc.terminate() except AttributeError: from os import kill kill(self.proc.pid, 15) self.proc.wait() sys.stderr.flush() sys.stdout.flush()
def terminate(self): win32job.TerminateJobObject(self.hJob, 0)
#### Resume the process hThread = processInfo[1] if not win32process.ResumeThread(hThread): print 'ResumeThread failed, err=%s' % e[0] sys.exit(36) win32api.CloseHandle(hThread) #### Wait on the process and get the exit code try: win32event.WaitForSingleObject(hProcess, win32event.INFINITE) except pywintypes.error, e: print 'WaitForSingleObject failed, err=%s' % e[0] sys.exit(40) exitCode = win32process.GetExitCodeProcess(hProcess) #### Clean up win32api.CloseHandle(hProcess) win32job.TerminateJobObject(hJob, 0) win32api.CloseHandle(hJob) windll.user32.CloseDesktop(hDesktop) sys.exit(exitCode)