import multiprocessing.reduction # make sockets pickable/inheritable
multiprocessing.freeze_support() # Add support for when a program which uses multiprocessing has been frozen to produce a Windows executable.
-#ignore = multiprocessing.active_children() # cleanup any old processes
"""
This class handles port distribution for SALOME sessions.
class _ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
pass
+pm_address = ('127.0.0.1', 51843)
def __getServer(address):
SocketServer.ThreadingTCPServer.allow_reuse_address = True # can be restarted immediately
server = _ThreadedTCPServer(address, _ThreadedTCPRequestHandler, False) # Do not automatically bind
return server
#
-pm_address = ('localhost', 12345)
def __startServer():
+ global pm_address
try:
server = __getServer(pm_address)
server.server_bind() # Manually bind, to support allow_reuse_address
server.server_activate()
- address = server.server_address
+ pm_address = server.server_address
# Start a thread with the server -- that thread will then start one
# more thread for each request
#server_thread.setDaemon(True)
server_thread.start()
#print "Server loop running in thread:", server_thread.getName()
- #print "Server address:", address
+ #print "Server address:", pm_address
#return address
except:
#print "Server already started"
def __newClient(address, message):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ #print "connect client to", address
sock.connect(address)
_send(sock, message)
response = _receive(sock)
# Auto start: unique instance ; no effect if called multiple times
__startServer()
-#server_thread = threading.Thread(target=__startServer, name="SALOME_PortManager")
-#server_thread.setDaemon(True)
-#server_thread.start()
Returns first found free port number.
"""
- #import PortManager
- #client = PortManager.start_client() # :NOTE: might specify a (remote) IP
- #portManager = client.PortManager()
from PortManager import getPort
port = getPort(use_port)
- #PortManager.getPort()
- #PortManager.test_value()
-
if use_port:
print "Check if port can be used: %d" % use_port,
- #if not portManager.isPortUsed(use_port):
- if port == use_port:
+ if port == use_port and port != -1:
print "- OK"
__setup_config(use_port, args, save_config)
return
pass
#
print "Searching for a free port for naming service:",
- #port = portManager.getPort()
- print "%s - OK"%(port)
- __setup_config(port, args, save_config)
- #port = portManager.releasePort(port)
+ if port == -1: # try again
+ port = getPort(use_port)
+
+ if port != -1:
+ print "%s - OK"%(port)
+ __setup_config(port, args, save_config)
+ else:
+ print "Unable to obtain port"
#