]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
add a "--spy" option
authoradam <adam>
Fri, 1 Apr 2011 14:30:48 +0000 (14:30 +0000)
committeradam <adam>
Fri, 1 Apr 2011 14:30:48 +0000 (14:30 +0000)
bin/killSalomeWithPort.py

index 6eeceec530b9344775d46f22673a1bf17f4f2b16..abdf38e1739639a764238e2e46217e093dace429 100755 (executable)
@@ -261,8 +261,53 @@ def killNotifdAndClean(port):
       pass
 
     appliCleanOmniOrbConfig(port)
-    
+
+def killMyPortSpy(pid, port):
+    dt = 1.0
+    while 1:
+        from os import kill
+        try:
+            kill(int(pid), 0)
+        except OSError, e:
+            if e.errno != 3:
+                return
+            break
+        from time import sleep
+        sleep(dt)
+        pass
+    filedict = getPiDict(port, hidden=True)
+    if not os.path.exists(filedict):
+        return
+    try:
+        import omniORB
+        orb = omniORB.CORBA.ORB_init(sys.argv, omniORB.CORBA.ORB_ID)
+        import SALOME_NamingServicePy
+        ns = SALOME_NamingServicePy.SALOME_NamingServicePy_i(orb)
+        import SALOME
+        session = ns.Resolve("/Kernel/Session")
+        assert session
+    except:
+        return
+    try:
+        status = session.GetStatSession()
+    except:
+        # -- session is in naming service but has crash
+        status = None
+        pass
+    if status:
+        if not status.activeGUI:
+            return
+        pass
+    killMyPort(port)
+    return
+
 if __name__ == "__main__":
+    if sys.argv[1] == "--spy":
+        pid = sys.argv[2]
+        port = sys.argv[3]
+        killMyPortSpy(pid, port)
+        sys.exit(0)
+        pass
     for port in sys.argv[1:]:
         killMyPort(port)
         pass