# outside application context
return
- if verbose():
- print("Cleaning OmniOrb config for port {}".format(port))
+ logging.getLogger().debug("Cleaning OmniOrb config for port {}".format(port))
omniorb_config = generateFileName(omniorb_user_path,
prefix='omniORB',
extension='cfg',
hidden=True,
with_username=True)
-
- if os.access(last_running_config, os.F_OK):
- if sys.platform == 'win32' or (os.access(omniorb_config, os.F_OK) and \
- osp.samefile(last_running_config, omniorb_config)):
+ logging.getLogger().debug("Omniorb_config file deduced by port : {}".format(omniorb_config))
+ logging.getLogger().debug("Omniorb_config file of last : {}".format(last_running_config))
+ if osp.exists(last_running_config):
+ if sys.platform == 'win32' or ( osp.exists(omniorb_config) and osp.samefile(last_running_config,omniorb_config) ):
os.remove(last_running_config)
if os.access(omniorb_config, os.F_OK):
logger.debug("Add process with PID = {} into PIDList to kill".format(pid))
processes.append(psutil.Process(pid))
except psutil.NoSuchProcess:
- if verbose():
- print(" ------------------ Process {} not found".format(pid))
+ logger.debug(" ------------------ Process {} not found".format(pid))
__killProcesses(processes)
def __killMyPort(port, filedict):
return None
-def killMyPortSSL(*ports):
- """ Called by runSalome.py after CTRL-C"""
- for port in ports:
- # ensure port is an integer
- with suppress(ValueError):
- port = int(port)
-
- with suppress(Exception):
- # DO NOT REMOVE NEXT LINE: it tests PortManager availability!
- from PortManager import releasePort
- # get pidict file
- filedict = getPiDict(port)
- if not osp.isfile(filedict): # removed by previous call, see (1) above
- if verbose():
- print("SALOME session on port {} is already stopped".format(port))
- # remove port from PortManager config file
- with suppress(ImportError):
- if verbose():
- print("Removing port from PortManager configuration file")
- releasePort(port)
- return
- try:
- # DO NOT REMOVE NEXT LINE: it tests PortManager availability!
- import PortManager # pragma pylint: disable=unused-import
- for file_path in glob('{}*'.format(getPiDict(port))):
- __killMyPort(port, file_path)
- except ImportError:
- __killMyPort(port, __guessPiDictFilename(port))
+def killProcessSSL(port, pids_list):
+ """ Called by runSalome.py after CTRL-C.
+ This method :
+ - Kill all PIDS in pids
+ - update file of pidict
+ """
+ __killPids(pids_list)
- # clear-up omniOrb config files
- appliCleanOmniOrbConfig(port)
+ with suppress(ValueError):
+ port = int(port)
+
+ for filedict in glob('{}*'.format(getPiDict(port))):
+ with suppress(Exception), open(filedict, 'rb') as fpid:
+ logging.getLogger().debug("Removing following PIDS from file \"{}\" : {}"
+ .format(filedict,pids_list))
+ pids_lists_in_file = pickle.load(fpid)
+ for dico_of_pids in pids_lists_in_file:
+ for pid in pids_list:
+ if pid in dico_of_pids:
+ del dico_of_pids[pid]
+ pids_lists_in_file = [elt for elt in pids_lists_in_file if len(elt)>0]
+ if len(pids_lists_in_file) == 0:
+ try:
+ logging.getLogger().debug("List of PIDS to Kill is now empty -> Remove file \"{}\"".format(filedict))
+ os.remove(filedict)
+ except:
+ pass
+ continue
+ with suppress(Exception), open(filedict, 'wb') as fpid:
+ logging.getLogger().debug("Writing back into file \"{}\"".format(filedict))
+ pickle.dump(pids_lists_in_file,fpid)
+ # clear-up omniOrb config files
+ appliCleanOmniOrbConfig(port)
def killMyPort(*ports):
"""
# -----------------------------------------------------------------------------
-def addToPidict(args):
- global process_id
- from addToKillList import addToKillList
- for pid, cmd in list(process_id.items()):
- addToKillList(pid, cmd)
-
-# -----------------------------------------------------------------------------
-
def main(exeName=None):
"""Salome launch as a main application"""
keep_env = not os.getenv('SALOME_PLEASE_SETUP_ENVIRONMENT_AS_BEFORE')
ior_fakens_filename = useSalome(args, modules_list, modules_root_dir)
# Management of -t <script.py>
toimport = []
+ env = os.environ
if 'gui' in args and 'session_gui' in args:
if not args['gui'] or not args['session_gui']:
if 'study_hdf' in args:
toopen = args['study_hdf']
if toopen:
- import salome
- salome.salome_init(path=toopen)
+ os.environ["PATH_TO_STUDY_FILE_TO_INITIATE"] = toopen
+ logger.debug("An input Study has been specified {} -> pass it with PATH_TO_STUDY_FILE_TO_INITIATE env var".format(toopen))
if 'pyscript' in args:
toimport = args['pyscript']
from salomeContextUtils import formatScriptsAndArgs
command = formatScriptsAndArgs(toimport, escapeSpaces=True)
if command:
logger.debug("Launching following shell command : {}".format(str(command)))
- proc = subprocess.Popen(command, shell=True)
+ proc = subprocess.Popen(command, shell=True, env = env)
addToKillList(proc.pid, command)
res = proc.wait()
if res: sys.exit(1)
from salome_utils import getPortNumber
port = getPortNumber()
# --
- server = Server({})
- if sys.platform == "win32":
- 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(True)
- # os.system("killSalomeWithPort.py --spy %s %s &"%(os.getpid(), port))
- # --
dt = 1.0
try:
while 1:
pass
except KeyboardInterrupt:
logger.debug("Keyboard requested : killing all process attached to port {}".format(port))
- from killSalomeWithPort import killMyPortSSL
- killMyPortSSL(port)
- pass
+ finally:
+ from killSalomeWithPort import killProcessSSL
+ killProcessSSL(port,[session_pid])
return
#