Esempio n. 1
0
File: oof.py Progetto: creuzige/OOF2
def start_sockets_Front_End():
    if parallel_enable.enabled():
        try:
            from ooflib.SWIG.common import mpitools
        except ImportError:
            raise ooferror.ErrSetupError(
                "Parallel option requested, but parallel code not present.")
        from ooflib.common.IO import socket2me
        ## Tell back end what port to listen
        s_name = mpitools.Get_processor_name()
        s_address = socket2me.socketPort.getPort()
        mpitools.bcast_string("%i" % s_address, 0)
        mpitools.bcast_string(s_name, 0)
        ## Tell back end the number of processors on the back end
        socket2me.socketPort.connect(mpitools.Size() - 1)
Esempio n. 2
0
    def __init__(self, host, port, MPIrank):
        local_name = mpitools.Get_processor_name()
        # If the "server" is on the same machine as the SocketInput,
        # then the ssh process can become confused -- hosts don't
        # always know themselves, and there can be name-resolution
        # issues if a host has several interfaces and/or names.  So, in
        # this case, just connect directly.
        if local_name == host:
            self.comm = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.comm.connect((local_name, port))
        else:
            if SSH_TUNNEL:
                host_name = "127.0.0.1"
                proto = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                proto.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                proto.bind((host_name, socket.INADDR_ANY))
                nearport = proto.getsockname()[1]

                # Build and run the appropriate ssh command.
                ssh_cmd = "ssh -L %d:127.0.0.1:%d %s -N" % \
                          (nearport, port, host)
                os.popen2(ssh_cmd)
                proto.close()  # Discard the socket.
            else:
                # Non-ssh -- direct connection.
                host_name = host
                nearport = port

            c_count = 0

            while c_count < SocketInput.connection_attempt_limit:
                try:
                    c_count += 1
                    self.comm = socket.socket(socket.AF_INET,
                                              socket.SOCK_STREAM)
                    self.comm.connect((host_name, nearport))
                except socket.error, e:
                    if e[0] == errno.ECONNREFUSED:  # "Connection refused"
                        self.comm.close()
                        time.sleep(0.1)
                    else:
                        self.comm.close()
                        raise

                else:
                    break
                # If we didn't break out, then we're up to the limit.
            else: