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
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:
# 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:
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
#
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
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: