]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Management of salome -t <script.py>
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 23 Feb 2022 09:45:52 +0000 (10:45 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 23 Feb 2022 09:45:52 +0000 (10:45 +0100)
bin/killSalomeWithPort.py
bin/runSalome.py
bin/salomeContext.py

index 5375452df8317cebcae2b9639e7902b7c21d9042..04e6939f6702a96ef1826388d28fcc9e82b62a4a 100755 (executable)
@@ -65,6 +65,8 @@ import psutil
 
 from salome_utils import (generateFileName, getHostName, getLogDir, getShortHostName,
                           getUserName, killOmniNames, killPid, verbose)
+import logging
+logger = logging.getLogger()
 
 def getPiDict(port, appname='salome', full=True, hidden=True, hostname=None):
     """
@@ -247,6 +249,7 @@ def __killPids(pids):
     processes = []
     for pid in pids:
         try:
+            logger.debug("Add process with PID = {} into PIDList to kill".format(pid))
             processes.append(psutil.Process(pid))
         except psutil.NoSuchProcess:
             if verbose():
@@ -262,7 +265,7 @@ def __killMyPort(port, filedict):
     # ensure port is an integer
     with suppress(ValueError):
         port = int(port)
-
+    logger.debug("Into __killMyPort with port {}. File containing PID to kill is {}".format(port,filedict))
     # read pids from pidict file
     with suppress(Exception), open(filedict, 'rb') as fpid:
         pids_lists = pickle.load(fpid)
index 20f3da436b1fa1d6a045127e41e817b75454255f..76ab5872f1d7d834e4067c35025cd7f84a25b992 100755 (executable)
@@ -80,6 +80,7 @@ def startSalome(args, modules_list, modules_root_dir):
         mySessionServ.setpath(modules_list,modules_root_dir)
         mySessionServ.run()
         ior_fakens_filename = mySessionServ.iorfakens
+        logger.debug("Rendez-vous file for to retrieve IOR of session is \"{}\"".format(ior_fakens_filename))
     
     end_time = os.times()
 
@@ -174,7 +175,7 @@ def addToPidict(args):
     global process_id
     from addToKillList import addToKillList
     for pid, cmd in list(process_id.items()):
-        addToKillList(pid, cmd, args['port'])
+        addToKillList(pid, cmd)
 
 # -----------------------------------------------------------------------------
 
@@ -187,6 +188,26 @@ def main(exeName=None):
     # --
     setenv.set_env(args, modules_list, modules_root_dir, keepEnvironment=keep_env)
     ior_fakens_filename = useSalome(args, modules_list, modules_root_dir)
+    ###
+    toimport = []
+    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)
+            if 'pyscript' in args:
+                toimport = args['pyscript']
+    from salomeContextUtils import formatScriptsAndArgs
+    from addToKillList import addToKillList
+    command = formatScriptsAndArgs(toimport, escapeSpaces=True)
+    if command:
+        logger.debug("Launching following shell command : {}".format(str(command)))
+        proc = subprocess.Popen(command, shell=True)
+        addToKillList(proc.pid, command)
+        res = proc.wait()
+        if res: sys.exit(1) 
     return args, ior_fakens_filename
 
 # -----------------------------------------------------------------------------
@@ -273,12 +294,14 @@ def foreGround(args, ior_fakens_filename):
                 status = session.GetStatSession()
                 assert status.activeGUI
             except Exception:
+                logger.debug("Process of the session under monitoring {} has vanished !".format(session_pid))
                 break
             from time import sleep
             sleep(dt)
             pass
         pass
     except KeyboardInterrupt:
+        logger.debug("Keyboard requested : killing all process attached to port {}".format(port))
         from killSalomeWithPort import killMyPortSSL
         killMyPortSSL(port)
         pass
index 3cdc0c0a0a93299f1da20e5e864971a70ce30049..6597d9a5fa15e8054f70de0591dea8982f4a6fdb 100755 (executable)
@@ -353,6 +353,7 @@ class SalomeContext:
       args = []
     # Initialize SALOME environment
     sys.argv = ['runSalomeOld'] + args
+    print(477*"!"+str(sys.argv))
     import setenv
     setenv.main(True, exeName="salome withsession")
 
@@ -365,9 +366,10 @@ class SalomeContext:
     if args is None:
       args = []
     sys.argv = ['runSalome'] + args
+    print(477*"@"+str(sys.argv))
     import setenv
     setenv.main(True, exeName="salome withsession")
-    
+
     import runSalome
     runSalome.runSalome()
     return 0