From 70ccdfa1ed4c233ebab0a54c1e909923f6276699 Mon Sep 17 00:00:00 2001 From: ana Date: Fri, 27 Nov 2015 18:59:40 +0300 Subject: [PATCH] Win32: fix problems with SALOME killing --- bin/salome_utils.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/bin/salome_utils.py b/bin/salome_utils.py index 186ed8da2..1933c1b56 100644 --- a/bin/salome_utils.py +++ b/bin/salome_utils.py @@ -486,9 +486,17 @@ def setVerbose(level): # -- import signal -def killpid(pid, sig = signal.SIGKILL): +def killpid(pid, sig = 9): """ - Try to kill process by pid. + Send signal sig to the process by pid. + + Parameters: + - pid : PID of process + - sig : signal for sending + Possible values of signals: + 9 means kill the process + 0 only check existing of the process + NOTE: Other values are not processed on Windows Returns: 1 Success 0 Fail, no such process @@ -497,15 +505,28 @@ def killpid(pid, sig = signal.SIGKILL): """ if not pid: return import os, sys - if verbose(): print "######## killpid pid = ", pid + if sig != 0: + if verbose(): print "######## killpid pid = ", pid try: if sys.platform == "win32": import ctypes - handle = ctypes.windll.kernel32.OpenProcess(1, False, int(pid)) - ret = ctypes.windll.kernel32.TerminateProcess(handle, -1) - ctypes.windll.kernel32.CloseHandle(handle) + if sig == 0: + # PROCESS_QUERY_INFORMATION (0x0400) Required to retrieve certain information about a process + handle = ctypes.windll.kernel32.OpenProcess(0x0400, False, int(pid)) + if handle: + ret = 1 + ctypes.windll.kernel32.CloseHandle(handle) + else: + ret = 0 + if sig == 9: + # PROCESS_TERMINATE (0x0001) Required to terminate a process using TerminateProcess. + handle = ctypes.windll.kernel32.OpenProcess(0x0001, False, int(pid)) + ret = ctypes.windll.kernel32.TerminateProcess(handle, -1) + ctypes.windll.kernel32.CloseHandle(handle) + pass pass else: + # Default: signal.SIGKILL = 9 os.kill(int(pid),sig) ret = 1 pass -- 2.39.2