From: Cédric Aguerre Date: Tue, 21 Mar 2017 13:39:30 +0000 (+0100) Subject: [PortManager] Separate ports according to their owner (this or other application) X-Git-Tag: SHAPER_2.7.0~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=57148ef1d1aba40ec2e2e0cf22ab5f9256d05bc3;p=modules%2Fkernel.git [PortManager] Separate ports according to their owner (this or other application) --- diff --git a/bin/PortManager.py b/bin/PortManager.py index 53ebacea9..dfae43a80 100644 --- a/bin/PortManager.py +++ b/bin/PortManager.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2007-2017 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 @@ -29,6 +29,9 @@ try: except: import pickle #@Reimport +__PORT_MIN_NUMBER = 2810 +__PORT_MAX_NUMBER = 2910 + import logging def createLogger(): logger = logging.getLogger(__name__) @@ -144,24 +147,28 @@ def getPort(preferedPort=None): logger.debug("load busy_ports: %s"%str(config["busy_ports"])) # append port - busy_ports = config["busy_ports"] + ports_info = config["busy_ports"] + busy_ports = [x[0] for x in ports_info] port = preferedPort if not port or __isPortUsed(port, busy_ports): - port = 2810 + port = __PORT_MIN_NUMBER while __isPortUsed(port, busy_ports): - if port == 2810+100: + if port == __PORT_MAX_NUMBER: msg = "\n" msg += "Can't find a free port to launch omniNames\n" 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 config["busy_ports"]: - config["busy_ports"].append(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) + config["busy_ports"].append((port,"this")) - # write config + # 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: @@ -200,13 +207,13 @@ def releasePort(port): logger.debug("load busy_ports: %s"%str(config["busy_ports"])) # remove port from list - busy_ports = config["busy_ports"] - - if port in busy_ports: - busy_ports.remove(port) - config["busy_ports"] = busy_ports + ports_info = config["busy_ports"] + config["busy_ports"] = [x for x in ports_info if x[0] != port] - # write config + # 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: @@ -223,7 +230,6 @@ def releasePort(port): # def getBusyPorts(): - busy_ports = [] config_file, lock_file = _getConfigurationFilename() oldmask = os.umask(0) with open(lock_file, 'w') as lock: @@ -241,10 +247,23 @@ def getBusyPorts(): logger.debug("load busy_ports: %s"%str(config["busy_ports"])) - busy_ports = 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] + 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")) + + logger.debug("all busy_ports: %s"%str(config["busy_ports"])) + + ports_info = config["busy_ports"] + ports_info.sort(key=lambda x: x[0]) + # release lock __release_lock(lock) os.umask(oldmask) - return busy_ports + return ports_info # diff --git a/bin/salomeContext.py b/bin/salomeContext.py index 78e5d5765..86aa86a8f 100644 --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@ -395,11 +395,12 @@ class SalomeContext: if ports: import tempfile - for port in ports: - with tempfile.NamedTemporaryFile(): - p = Process(target = killMyPort, args=(port,)) - p.start() - p.join() + for port,owner in ports: + if owner == "this": + with tempfile.NamedTemporaryFile(): + p = Process(target = killMyPort, args=(port,)) + p.start() + p.join() except ImportError: # :TODO: should be declared obsolete from killSalome import killAllPorts @@ -473,7 +474,7 @@ Available options are: ports = PortManager.getBusyPorts() print "SALOME instances are running on ports:", ports if ports: - print "Last started instance on port %s"%ports[-1] + print "Last started instance on port %s"%ports[-1][0] if "-s" in args or "--softwares" in args: if "-s" in args: