Ejemplo n.º 1
0
    def master_init_slaves(cls,
                           num_weights,
                           slaves=(),
                           timeout=None,
                           limit=65536,
                           master_oversees=False,
                           **kwargs):
        """Initialize proxies for each of the slaves and block on a working
        connection.
        """
        # Initialize server proxies for the slaves
        srv_timeout = 3 * timeout if timeout is not None else 1000
        all_machines = [] if master_oversees else [None]
        for slave in slaves:
            host, port = slave.split(':')
            all_machines.append(
                jsonrpc.ServerProxy(
                    jsonrpc.JsonRpc20(),
                    jsonrpc.TransportTcpIp(addr=(host, int(port)),
                                           limit=limit,
                                           timeout=srv_timeout)))

            # Block on a working connection to each slave
            machine_idx = len(all_machines) - 1
            working_connection = False
            while not working_connection:
                try:
                    cls.call_slave(all_machines[machine_idx],
                                   'slave_init_weights', num_weights)
                    working_connection = True
                except jsonrpc.RPCTransportError:
                    print "Waiting to establish connection to slave", slave
                    time.sleep(10)
        return all_machines
Ejemplo n.º 2
0
 def from_server(cls, host_port):
     """Return a proxy Gigaword object with bound methods to
     retrieve counts.
     """
     host, port = host_port.split(':')
     return jsonrpc.ServerProxy(
         jsonrpc.JsonRpc20(),
         jsonrpc.TransportTcpIp(addr=(host, int(port))))
Ejemplo n.º 3
0
 def from_server(cls, host_port, timeout=60):
     """Return a proxy LM object with bound methods to support ngram
     scoring.
     """
     if host_port is None:
         return None
     host, port = host_port.split(':')
     return jsonrpc.ServerProxy(jsonrpc.JsonRpc20(),
             jsonrpc.TransportTcpIp(addr=(host, int(port)),
                                    timeout=timeout))
Ejemplo n.º 4
0
 def from_server(cls, host_port, timeout=60):
     """Return a proxy DependencyModel object with bound methods to
     support retrieval of dependency probabiities.
     """
     if host_port is None:
         return None
     host, port = host_port.split(':')
     return jsonrpc.ServerProxy(
         jsonrpc.JsonRpc20(),
         jsonrpc.TransportTcpIp(addr=(host, int(port)), timeout=timeout))