import omniORB
orb = omniORB.CORBA.ORB_init(sys.argv, omniORB.CORBA.ORB_ID)
import SALOME_NamingServicePy
- ns = SALOME_NamingServicePy.SALOME_NamingServicePy_i(orb)
+ ns = SALOME_NamingServicePy.SALOME_NamingServicePy_i(orb, 3, True)
import SALOME #@UnresolvedImport @UnusedImport
session = ns.Resolve("/Kernel/Session")
assert session
except:
+ killMyPort(port)
return
try:
status = session.GetStatSession()
server.CMD = [os.getenv("PYTHONBIN"), "-m", "killSalomeWithPort", "--spy", "%s"%(session_pid or os.getpid()), "%s"%(port)]
else:
server.CMD = ["killSalomeWithPort.py", "--spy", "%s"%(session_pid or os.getpid()), "%s"%(port)]
- server.run()
+ server.run(True)
# os.system("killSalomeWithPort.py --spy %s %s &"%(os.getpid(), port))
# --
dt = 1.0
test = test and args['foreground']
# --
if test:
+ from time import sleep
+ sleep(3.0)
foreGround(clt, args)
pass
pass
-1 Fail, another reason
"""
- if not pid: return
- import os, sys
- if sig != 0:
+ if not pid:
+ return
+
+ if sig == 0:
+ ret = 1 if psutil.pid_exists(int(pid)) else 0
+ else:
if verbose(): print("######## killpid pid = ", pid)
- try:
- if sys.platform == "win32":
- import ctypes
- if sig == 0:
- # PROCESS_QUERY_INFORMATION (0x0400) Required to retrieve certain information about a process
- handle = ctypes.windll.kernel32.OpenProcess(0x0400, False, int(pid))
- if handle:
- ret = 1
- ctypes.windll.kernel32.CloseHandle(handle)
- else:
- ret = 0
- if sig == 9:
- # PROCESS_TERMINATE (0x0001) Required to terminate a process using TerminateProcess.
- handle = ctypes.windll.kernel32.OpenProcess(0x0001, False, int(pid))
- ret = ctypes.windll.kernel32.TerminateProcess(handle, -1)
- ctypes.windll.kernel32.CloseHandle(handle)
- pass
- pass
- else:
- # Default: signal.SIGKILL = 9
- os.kill(int(pid),sig)
+ try:
+ proc = psutil.Process(int(pid))
+ proc.terminate()
+ _, alive = psutil.wait_procs([proc], timeout=5)
+ for p in alive:
+ p.kill()
ret = 1
- pass
- pass
- except OSError as e:
- # errno.ESRCH == 3 is 'No such process'
- if e.errno == 3:
+ except psutil.NoSuchProcess:
ret = 0
- else:
+ except OSError:
ret = -1
- pass
- pass
return ret
# --
else:
raise Exception("Unsupported server launch mode: %s" % mode)
- def run(self):
+ def run(self, daemon=False):
global process_id
myargs=self.ARGS
if self.args.get('xterm'):
# print("command = ", command)
if sys.platform == "win32":
import subprocess
- pid = subprocess.Popen(command).pid
+ if daemon:
+ DETACHED_PROCESS = 0x00000008
+ pid = subprocess.Popen(command, creationflags=DETACHED_PROCESS).pid
+ else:
+ pid = subprocess.Popen(command).pid
elif Server.server_launch_mode == "fork":
pid = os.spawnvp(os.P_NOWAIT, command[0], command)
else: # Server launch mode is daemon
#-------------------------------------------------------------------------
- def __init__(self, orb=None):
+ def __init__(self, orb=None, steps=240, spy=False):
"""
Standard Constructor, with ORB reference.
self._orb = orb
# initialize root context and current context
ok = 0
- steps = 240
while steps > 0 and ok == 0:
try:
obj =self._orb.resolve_initial_references("NameService")
steps = steps - 1
if steps == 0 and self._root_context is None:
MESSAGE ( "Name Service Reference is invalid" )
- sys.exit(1)
+ if spy:
+ raise ValueError("Name Service Reference is invalid")
+ else:
+ sys.exit(1)
#-------------------------------------------------------------------------