Salome HOME
typo-fix by Kunda
[modules/yacs.git] / bin / killSalomeWithPort.py
index 31eaceb1b90b4277655241441766e8caa59683a3..01d1eb39a2b9546e22a56162ec5c96d4e8e8de5a 100755 (executable)
@@ -1,6 +1,6 @@
 #! /usr/bin/env python
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2017  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -214,12 +214,12 @@ def shutdownMyPort(port, cleanup=True):
         pass
     except:
         pass
-    exit(0) # see (1)
+    sys.exit(0) # see (1)
     pass
 # (1) If --shutdown-servers option is set to 1, session close procedure is
-# called twice: first explicitely by salome command, second by automatic
+# called twice: first explicitly by salome command, second by automatic
 # atexit to handle Ctrl-C. During second call, LCC does not exist anymore and
-# a RuntimeError is raised; we explicitely exit this function with code 0 to
+# a RuntimeError is raised; we explicitly exit this function with code 0 to
 # prevent parent thread from crashing.
 
 def __killMyPort(port, filedict):
@@ -311,7 +311,7 @@ def killMyPort(port):
 
     # try to shutdown session normally
     import threading, time
-    threading.Thread(target=shutdownMyPort, args=(port,False)).start()
+    threading.Thread(target=shutdownMyPort, args=(port,True)).start()
     time.sleep(3) # wait a little, then kill processes (should be done if shutdown procedure hangs up)
 
     try:
@@ -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