From: aguerre Date: Fri, 4 Oct 2013 12:27:55 +0000 (+0000) Subject: Changing socket X-Git-Tag: begin_agr_portmanager_branch_131004 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c450927234a53dcec2383780ec643d0e830c32cf;p=modules%2Fkernel.git Changing socket --- diff --git a/bin/PortManager.py b/bin/PortManager.py index cd9664b51..da1e06cd6 100644 --- a/bin/PortManager.py +++ b/bin/PortManager.py @@ -43,7 +43,6 @@ if sys.platform == 'win32': 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. @@ -189,6 +188,7 @@ class _ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler): 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 @@ -196,13 +196,13 @@ def __getServer(address): 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 @@ -211,7 +211,7 @@ def __startServer(): #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" @@ -223,6 +223,7 @@ def __startServer(): 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) @@ -257,6 +258,3 @@ def stopServer(): # 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() diff --git a/bin/searchFreePort.py b/bin/searchFreePort.py index 4b5d0ca19..bda4863c0 100644 --- a/bin/searchFreePort.py +++ b/bin/searchFreePort.py @@ -70,19 +70,12 @@ def searchFreePort(args={}, save_config=1, use_port=None): 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 @@ -91,8 +84,12 @@ def searchFreePort(args={}, save_config=1, use_port=None): 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" #