Exemple #1
0
    def __init__(self, manager_address, worker_address):
        self._log = logging.getLogger(self.__class__.__name__)

        # Track the last action future.
        self._act_future = None

        self._manager_channel = grpc.insecure_channel(
            f"{manager_address[0]}:{manager_address[1]}")
        self._worker_address = worker_address
        self._worker_channel = grpc.insecure_channel(
            f"{worker_address[0]}:{worker_address[1]}")
        try:
            # Wait until the grpc server is ready or timeout after 30 seconds.
            grpc.channel_ready_future(self._manager_channel).result(timeout=30)
            grpc.channel_ready_future(self._worker_channel).result(timeout=30)
        except grpc.FutureTimeoutError as e:
            raise RemoteAgentException(
                "Timeout while connecting to remote worker process.") from e
        self._manager_stub = manager_pb2_grpc.ManagerStub(
            self._manager_channel)
        self._worker_stub = worker_pb2_grpc.WorkerStub(self._worker_channel)
Exemple #2
0
    def __init__(
        self,
        manager_address: Tuple[str, int],
        worker_address: Tuple[str, int],
        timeout: float = 10,
    ):
        """Executes an agent in a worker (i.e., a gRPC server).

        Args:
            manager_address (Tuple[str,int]): Manager's server address (ip, port).
            worker_address (Tuple[str,int]): Worker's server address (ip, port).
            timeout (float, optional): Time (seconds) to wait for startup or response from
                server. Defaults to 10.

        Raises:
            RemoteAgentException: If timeout occurs while connecting to the manager or worker.
        """
        self._log = logging.getLogger(self.__class__.__name__)

        # Track the last action future.
        self._act_future = None

        self._manager_channel = grpc.insecure_channel(
            f"{manager_address[0]}:{manager_address[1]}")
        self._worker_address = worker_address
        self._worker_channel = grpc.insecure_channel(
            f"{worker_address[0]}:{worker_address[1]}")
        try:
            # Wait until the grpc server is ready or timeout seconds.
            grpc.channel_ready_future(
                self._manager_channel).result(timeout=timeout)
            grpc.channel_ready_future(
                self._worker_channel).result(timeout=timeout)
        except grpc.FutureTimeoutError as e:
            raise RemoteAgentException(
                "Timeout while connecting to remote worker process.") from e
        self._manager_stub = manager_pb2_grpc.ManagerStub(
            self._manager_channel)
        self._worker_stub = worker_pb2_grpc.WorkerStub(self._worker_channel)