我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用win32process.TerminateProcess()。
def execute (cmd, timeout = 0): if timeout == 0: timeout = win32event.INFINITE info = win32process.CreateProcess(None, cmd, None, None, 0, 0, None, None, win32process.STARTUPINFO()) subprocess = info [0] rc = win32event.WaitForSingleObject (subprocess, timeout) if rc == win32event.WAIT_FAILED: return -1 if rc == win32event.WAIT_TIMEOUT: try: win32process.TerminateProcess (subprocess, 0) except pywintypes.error: return -3 return -2 if rc == win32event.WAIT_OBJECT_0: return win32process.GetExitCodeProcess(subprocess)
def timeout_execute (cmd, timeout = 0): if timeout == 0: timeout = win32event.INFINITE info = win32process.CreateProcess(None, cmd, None, None, 0, 0, None, None, win32process.STARTUPINFO()) subprocess = info [0] rc = win32event.WaitForSingleObject (subprocess, timeout) if rc == win32event.WAIT_FAILED: return -1 if rc == win32event.WAIT_TIMEOUT: try: win32process.TerminateProcess (subprocess, 0) except pywintypes.error: return -3 return -2 if rc == win32event.WAIT_OBJECT_0: return win32process.GetExitCodeProcess(subprocess)
def signalProcess(self, signalID): if signalID in ("INT", "TERM", "KILL"): win32process.TerminateProcess(self.hProcess, 1)
def kill(self, gracePeriod=5000): """ Kill process. Try for an orderly shutdown via WM_CLOSE. If still running after gracePeriod (5 sec. default), terminate. """ win32gui.EnumWindows(self.__close__, 0) if self.wait(gracePeriod) != win32event.WAIT_OBJECT_0: win32process.TerminateProcess(self.hProcess, 0) win32api.Sleep(100) # wait for resources to be released
def kill_win(process): """Kills a process with its windows handle. Has no effect on other platforms. """ try: # Unable to import 'module' # pylint: disable=import-error import win32process # Access to a protected member _handle of a client class # pylint: disable=protected-access return win32process.TerminateProcess(process._handle, -1) except ImportError: pass
def signalProcess(self, signalID): if self.pid is None: raise error.ProcessExitedAlready() if signalID in ("INT", "TERM", "KILL"): win32process.TerminateProcess(self.hProcess, 1)
def TerminateProc(cls, whd): win32process.TerminateProcess(whd,0)