Salome HOME
Merge branch 'V9_9_BR'
[modules/kernel.git] / bin / server.py
old mode 100755 (executable)
new mode 100644 (file)
index 2712c88..4412a93
@@ -1,6 +1,5 @@
-#!/usr/bin/env python3
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -25,6 +24,7 @@
 import os, sys, string
 from salome_utils import getHostName
 process_id = {}
+import logging
 
 # -----------------------------------------------------------------------------
 #
@@ -57,7 +57,7 @@ class Server:
       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'):
@@ -71,10 +71,19 @@ class Server:
                                    + os.getenv("LD_LIBRARY_PATH")]
               myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path
         command = myargs + self.CMD
+        for sapcfg in ["SalomeAppSLConfig","SalomeAppConfig"]:
+          if sapcfg in os.environ:
+            logging.getLogger().debug("{}={}".format(sapcfg,os.environ[sapcfg]))
+        command1 = (" ".join(command)).replace("(","\\\(") ; command1 = command1.replace(")","\\\)")
+        logging.getLogger().debug("Command to be launched : {}".format(command1))
         # 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
@@ -83,6 +92,7 @@ class Server:
           #store process pid if it really exists
           process_id[pid]=self.CMD
         self.PID = pid
+        logging.getLogger().debug("PID of launched command : {}".format(pid))
         return pid
 
     def daemonize(self,args):
@@ -108,7 +118,7 @@ class Server:
           try:
             os.kill(childpid,0)
             return childpid
-          except:
+          except Exception:
             return None
 
         #first child