From: vsr Date: Wed, 25 Nov 2015 16:37:24 +0000 (+0300) Subject: One more commit to fix problems with SALOME killing causing by previous changes. X-Git-Tag: V8_0_0a1~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6ce715f67787a38ce287c7611205c64c4974ba67;p=modules%2Fkernel.git One more commit to fix problems with SALOME killing causing by previous changes. --- diff --git a/bin/killSalomeWithPort.py b/bin/killSalomeWithPort.py index 31eaceb1b..bcb961016 100755 --- a/bin/killSalomeWithPort.py +++ b/bin/killSalomeWithPort.py @@ -354,14 +354,12 @@ def cleanApplication(port): def killMyPortSpy(pid, port): dt = 1.0 while 1: - try: - from salome_utils import killpid - killpid(int(pid)) - except OSError, e: - if e.errno != 3: - return + from salome_utils import killpid + ret = killpid(int(pid), 0) + if ret == 0: break - pass + elif ret < 0: + return from time import sleep sleep(dt) pass diff --git a/bin/salome_utils.py b/bin/salome_utils.py index 2dbe6b364..186ed8da2 100644 --- a/bin/salome_utils.py +++ b/bin/salome_utils.py @@ -485,21 +485,40 @@ def setVerbose(level): return # -- -def killpid(pid): +import signal +def killpid(pid, sig = signal.SIGKILL): """ - Kill process by pid. + Try to kill process by pid. + Returns: + 1 Success + 0 Fail, no such process + -1 Fail, another reason + """ if not pid: return - import os,sys,signal + import os, sys if verbose(): print "######## killpid pid = ", pid - if sys.platform == "win32": - import ctypes - handle = ctypes.windll.kernel32.OpenProcess(1, False, int(pid)) - ctypes.windll.kernel32.TerminateProcess(handle, -1) - ctypes.windll.kernel32.CloseHandle(handle) - else: - os.kill(int(pid),signal.SIGKILL) + 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) + pass + else: + os.kill(int(pid),sig) + ret = 1 + pass + pass + except OSError, e: + # errno.ESRCH == 3 is 'No such process' + if e.errno == 3: + ret = 0 + else: + ret = -1 + pass pass + return ret # -- def getOmniNamesPid(port):