import os, sys, re, signal
-from killSalomeWithPort import killMyPort, getPiDict
+from killSalomeWithPort import killMyPort, getPiDict, checkUnkilledProcess
#from salome_utils import getHostName, getShortHostName
from salome_utils import getUserName
except:
pass
# kill other processes
- if sys.platform != 'win32':
- import subprocess
- cmd = "ps -fea | grep '%s' | grep 'ghs3d' | grep 'f /tmp/GHS3D_' | grep -v 'grep' | awk '{print $2}'" % user
- prc = subprocess.getoutput(cmd)
- for field in prc.split():
- try:
- os.kill(int(field), signal.SIGKILL)
- except:
- pass
- pass
- pass
- # kill ompi-server needed for MPI containers coupling
- cmd = "ps -fea | grep '%s' | grep 'ompi-server' | grep -v 'grep' | awk '{print $2}'" % user
- prc = subprocess.getoutput(cmd)
- for field in prc.split():
- try:
- os.kill(int(field), signal.SIGKILL)
- except:
- pass
+ for pid in checkUnkilledProcess():
+ try:
+ os.kill(pid, signal.SIGKILL)
+ except:
pass
pass
+ if sys.platform != 'win32':
# delete uri files needed by ompi-server
cmd = "rm -f " + os.path.expanduser("~") + "/.urifile_*"
os.system(cmd)
# \endcode
#
-import os, sys, pickle, signal, subprocess,glob
+import re, os, sys, pickle, signal, glob
import subprocess
import shlex
from salome_utils import verbose
process_ids=pickle.load(fpid)
for process_id in process_ids:
for pid, cmd in list(process_id.items()):
+ pid = int(pid)
if verbose(): print("stop process %s : %s"% (pid, cmd[0]))
try:
from salome_utils import killpid
- killpid(int(pid))
+ killpid(pid)
except:
if verbose(): print(" ------------------ process %s : %s not found"% (pid, cmd[0]))
+ if pid in checkUnkilledProcess():
+ try:
+ killpid(pid)
+ except:
+ pass
pass
pass # for pid ...
pass # for process_id ...
dt = 1.0
while 1:
from salome_utils import killpid
- ret = killpid(int(pid), 0)
+ ret = killpid(pid, 0)
if ret == 0:
break
elif ret < 0:
killMyPort(port)
return
+def checkUnkilledProcess():
+ #check processes in system after kill
+ from salome_utils import getUserName
+ user = getUserName()
+ processes = dict()
+
+ if sys.platform != 'win32':
+
+ def _getDictfromOutput(_output, _dic, _cond = None):
+ _pids = dict(zip(list(map(int, _output[::2])), _output[1::2]))
+ if _cond:
+ _pids = {pid:cmd for pid,cmd in _pids.items() if re.match(_cond, cmd)}
+ _dic.update(_pids)
+
+ # 1. SALOME servers plus omniNames
+ cmd = 'ps --noheading -U {user} -o pid,cmd | awk \'{{printf("%s %s\\n", $1, $2)}}\''.format(user=user)
+ _getDictfromOutput(subprocess.getoutput(cmd).split(), processes, '^(SALOME_|omniNames)')
+ # 2. ghs3d
+ cmd = 'ps -fea | grep \'{user}\' | grep \'ghs3d\' | grep \'f /tmp/GHS3D_\' | grep -v \'grep\' | awk \'{{print("%s %s\\n", $2, $8)}}\''.format(user=user)
+ _getDictfromOutput(subprocess.getoutput(cmd).split(), processes)
+ # 3. ompi-server
+ cmd = 'ps -fea | grep \'{user}\' | grep \'ompi-server\' | grep -v \'grep\' | awk \'{{print("%s %s\\n", $2, $8)}}\''.format(user=user)
+ _getDictfromOutput(subprocess.getoutput(cmd).split(), processes)
+ else:
+ cmd = 'tasklist /fo csv | findstr /i "SALOME_ omniNames"'
+ prc = subprocess.getoutput(cmd)
+ try:
+ prc = prc.split()
+ prc = [prc[i].split(',') for i in range(0, len(prc)) if i % 2 == 0]
+ prc = dict([(int(prc[j][1].replace('"', '')), prc[j][0].replace('"', '')) for j in range(0, len(prc))])
+ processes.update(prc)
+ except:
+ pass
+ return processes
+
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: ")
pass
sys.exit(0)
pass
+ elif sys.argv[1] == "--find":
+ processes = checkUnkilledProcess()
+ if processes:
+ print("Unkilled processes: ")
+ print(" --------------------")
+ print(" PID : Process name")
+ print(" --------------------")
+ for pair in processes.items():
+ print('%6d : %s' % pair)
+ sys.exit(0)
try:
from salomeContextUtils import setOmniOrbUserPath #@UnresolvedImport
setOmniOrbUserPath()
#
clt=orbmodule.client(args)
+ addToPidict(args)
#
# Wake up session option
myServer=LoggerServer(args)
myServer.run()
clt.waitLogger("Logger")
+ addToPidict(args)
# Launch Session Server (to show splash ASAP)
#
mySessionServ = SessionServer(args,args['modules'],modules_root_dir)
mySessionServ.setpath(modules_list,modules_root_dir)
mySessionServ.run()
+ addToPidict(args)
#
# Launch Registry Server,
clt.waitNS("/Registry")
else:
clt.waitNSPID("/Registry",myServer.PID)
+ addToPidict(args)
#
# Launch Catalog Server,
clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog)
else:
clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog)
+ addToPidict(args)
#
# Launch SalomeDS Server,
clt.waitNS("/Study")
else:
clt.waitNSPID("/Study",myServer.PID)
+ addToPidict(args)
#
# Launch LauncherServer
myCmServer = LauncherServer(args)
myCmServer.setpath(modules_list,modules_root_dir)
myCmServer.run()
+ addToPidict(args)
#
# Launch ConnectionManagerServer
clt.waitNS("/Containers/" + theComputer + "/FactoryServer")
else:
clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID)
+ addToPidict(args)
if 'pyContainer' in args['standalone']:
raise Exception('Python containers no longer supported')
# -----------------------------------------------------------------------------
+def addToPidict(args):
+ global process_id
+ from addToKillList import addToKillList
+ for pid, cmd in list(process_id.items()):
+ addToKillList(pid, cmd, args['port'])
+
+# -----------------------------------------------------------------------------
+
def main(exeName=None):
"""Salome launch as a main application"""