From 0f9bf42d6003a683df48fe6ffcee81e0c88826e2 Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 20 Nov 2015 13:11:38 +0300 Subject: [PATCH] Fix for the bug 0023165: [CEA 1590] Salome 7.6.0 on Windows does not liberate the ports Additional change to previous commit, to fix regression with killing SALOME session. --- bin/killSalomeWithPort.py | 3 +++ bin/salome_utils.py | 13 +++++++++---- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 12 +++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/bin/killSalomeWithPort.py b/bin/killSalomeWithPort.py index 67d205c4a..a1057d8ad 100755 --- a/bin/killSalomeWithPort.py +++ b/bin/killSalomeWithPort.py @@ -245,6 +245,8 @@ def __killMyPort(port, filedict): except: print "Cannot find or open SALOME PIDs file for port", port pass + os.remove(filedict) + pass # def __guessPiDictFilename(port): @@ -347,6 +349,7 @@ def cleanApplication(port): pass appliCleanOmniOrbConfig(port) + pass def killMyPortSpy(pid, port): dt = 1.0 diff --git a/bin/salome_utils.py b/bin/salome_utils.py index b3efa8757..2dbe6b364 100644 --- a/bin/salome_utils.py +++ b/bin/salome_utils.py @@ -489,6 +489,7 @@ def killpid(pid): """ Kill process by pid. """ + if not pid: return import os,sys,signal if verbose(): print "######## killpid pid = ", pid if sys.platform == "win32": @@ -527,7 +528,7 @@ def getOmniNamesPid(port): # find Pid of omniNames pid = re.findall(r'Caption=.*omniNames.*\n?CommandLine=.*omniNames.*\D%s\D.*\n?ProcessId=(\d*)'%(port),allProc)[0] else: - cmd = r"ps -eo pid,command | grep -v grep | grep -E \"omniNames.*%s\""%(port) + cmd = "ps -eo pid,command | grep -v grep | grep -E \"omniNames.*%s\" | awk '{print $1}'"%(port) proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) pid = proc.communicate()[0] pass @@ -539,6 +540,10 @@ def killOmniNames(port): """ Kill OmniNames process by port number. """ - pid = getOmniNamesPid(port) - killpid(pid) -# -- \ No newline at end of file + try: + pid = getOmniNamesPid(port) + if pid: killpid(pid) + except: + pass + pass +# -- diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index e6db97ac9..966ab07d6 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -608,15 +608,16 @@ void SALOME_LifeCycleCORBA::killOmniNames() if ( !portNumber.empty() ) { - std::string cmd = ("from salome_utils import killOmniNames; "); + std::string cmd; + + cmd = std::string("from salome_utils import killOmniNames; "); cmd += std::string("killOmniNames(") + portNumber + "); "; cmd = python_exe + std::string(" -c \"") + cmd +"\""; MESSAGE(cmd); system( cmd.c_str() ); - cmd = ("from killSalomeWithPort import cleanApplication; "); + cmd = std::string("from killSalomeWithPort import cleanApplication; "); cmd += std::string("cleanApplication(") + portNumber + "); "; - //cmd = python_exe + std::string(" -c \"") + cmd +"\" > /dev/null 2> /dev/null"; cmd = python_exe + std::string(" -c \"") + cmd +"\""; MESSAGE(cmd); system( cmd.c_str() ); @@ -626,9 +627,10 @@ void SALOME_LifeCycleCORBA::killOmniNames() // shutdown portmanager if ( !portNumber.empty() ) { - std::string cmd = ("from PortManager import releasePort; "); + std::string cmd; + + cmd = std::string("from PortManager import releasePort; "); cmd += std::string("releasePort(") + portNumber + "); "; - //cmd = python_exe + std::string(" -c \"") + cmd +"\" > /dev/null 2> /dev/null"; cmd = python_exe + std::string(" -c \"") + cmd +"\""; MESSAGE(cmd); system( cmd.c_str() ); -- 2.39.2