]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[PortManager] Simplify previous fix; no need to change configuration file contents
authorCédric Aguerre <cedric.aguerre@edf.fr>
Wed, 22 Mar 2017 10:47:26 +0000 (11:47 +0100)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Wed, 22 Mar 2017 10:59:53 +0000 (11:59 +0100)
bin/PortManager.py
bin/salomeContext.py

index dfae43a80fc230e49fd617d579fa788a20bf20b5..18350254d1bc1918315b5cc0ea32470b2c630f46 100644 (file)
@@ -147,8 +147,7 @@ def getPort(preferedPort=None):
     logger.debug("load busy_ports: %s"%str(config["busy_ports"]))
 
     # append port
-    ports_info = config["busy_ports"]
-    busy_ports = [x[0] for x in ports_info]
+    busy_ports = config["busy_ports"]
     port = preferedPort
     if not port or __isPortUsed(port, busy_ports):
       port = __PORT_MIN_NUMBER
@@ -159,16 +158,11 @@ def getPort(preferedPort=None):
           msg += "Try to kill the running servers and then launch SALOME again.\n"
           raise RuntimeError, msg
         logger.debug("Port %s seems to be busy"%str(port))
-        if not port in busy_ports:
-          config["busy_ports"].append((port,"other"))
         port = port + 1
     logger.debug("found free port: %s"%str(port))
-    config["busy_ports"].append((port,"this"))
+    config["busy_ports"].append(port)
 
     # write config, for this application only (i.e. no 'other' ports)
-    logger.debug("all busy_ports: %s"%str(config["busy_ports"]))
-    ports_info = config["busy_ports"]
-    config["busy_ports"] = [x for x in ports_info if x[1] == "this"]
     logger.debug("write busy_ports: %s"%str(config["busy_ports"]))
     try:
       with open(config_file, 'w') as f:
@@ -208,12 +202,9 @@ def releasePort(port):
 
     # remove port from list
     ports_info = config["busy_ports"]
-    config["busy_ports"] = [x for x in ports_info if x[0] != port]
+    config["busy_ports"] = [x for x in ports_info if x != port]
 
     # write config, for this application only (i.e. no 'other' ports)
-    logger.debug("all busy_ports: %s"%str(config["busy_ports"]))
-    ports_info = config["busy_ports"]
-    config["busy_ports"] = [x for x in ports_info if x[1] == "this"]
     logger.debug("write busy_ports: %s"%str(config["busy_ports"]))
     try:
       with open(config_file, 'w') as f:
@@ -248,22 +239,24 @@ def getBusyPorts():
     logger.debug("load busy_ports: %s"%str(config["busy_ports"]))
 
     # Scan all possible ports to determine which ones are owned by other applications
-    ports_info = config["busy_ports"]
-    busy_ports = [x[0] for x in ports_info]
+    ports_info = { 'this': [], 'other': [] }
+    busy_ports = config["busy_ports"]
     for port in range(__PORT_MIN_NUMBER, __PORT_MAX_NUMBER):
       if __isPortUsed(port, busy_ports):
         logger.debug("Port %s seems to be busy"%str(port))
-        if not port in busy_ports:
-          config["busy_ports"].append((port,"other"))
+        if port in busy_ports:
+          ports_info["this"].append(port)
+        else:
+          ports_info["other"].append(port)
 
-    logger.debug("all busy_ports: %s"%str(config["busy_ports"]))
+    logger.debug("all busy_ports: %s"%str(ports_info))
 
-    ports_info = config["busy_ports"]
-    ports_info.sort(key=lambda x: x[0])
+    sorted_ports = { 'this': sorted(ports_info['this']),
+                     'other': sorted(ports_info['other']) }
 
     # release lock
     __release_lock(lock)
 
   os.umask(oldmask)
-  return ports_info
+  return sorted_ports
 #
index 86aa86a8f60b449014410f2bb1e97d0e23ddce8d..2b7ffad5dd91ba31396920ee29cff0c555cb510b 100644 (file)
@@ -391,16 +391,15 @@ class SalomeContext:
       import PortManager # mandatory
       from multiprocessing import Process
       from killSalomeWithPort import killMyPort
-      ports = PortManager.getBusyPorts()
+      ports = PortManager.getBusyPorts()['this']
 
       if ports:
         import tempfile
-        for port,owner in ports:
-          if owner == "this":
-            with tempfile.NamedTemporaryFile():
-              p = Process(target = killMyPort, args=(port,))
-              p.start()
-              p.join()
+        for port in ports:
+          with tempfile.NamedTemporaryFile():
+            p = Process(target = killMyPort, args=(port,))
+            p.start()
+            p.join()
     except ImportError:
       # :TODO: should be declared obsolete
       from killSalome import killAllPorts
@@ -472,9 +471,20 @@ Available options are:
     if "-p" in args or "--ports" in args:
       import PortManager
       ports = PortManager.getBusyPorts()
-      print "SALOME instances are running on ports:", ports
-      if ports:
-        print "Last started instance on port %s"%ports[-1][0]
+      this_ports = ports['this']
+      other_ports = ports['other']
+      if this_ports or other_ports:
+          print "SALOME instances are running on the following ports:"
+          if this_ports:
+              print "   This application:", this_ports
+          else:
+              print "   No SALOME instances of this application"
+          if other_ports:
+              print "   Other applications:", other_ports
+          else:
+              print "   No SALOME instances of other applications"
+      else:
+          print "No SALOME instances are running"
 
     if "-s" in args or "--softwares" in args:
       if "-s" in args: