]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
One more commit to fix problems with SALOME killing causing by previous changes.
authorvsr <vsr@opencascade.com>
Wed, 25 Nov 2015 16:37:24 +0000 (19:37 +0300)
committervsr <vsr@opencascade.com>
Wed, 25 Nov 2015 16:37:24 +0000 (19:37 +0300)
bin/killSalomeWithPort.py
bin/salome_utils.py

index 31eaceb1b90b4277655241441766e8caa59683a3..bcb9610169e4aba92c7728d1f999bf9ed6c1161c 100755 (executable)
@@ -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
index 2dbe6b3645fd48a286a7e16670bf6945fe910d81..186ed8da2459716f3d031b4452a18db5423ec8d0 100644 (file)
@@ -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):