Exemplo n.º 1
0
 def _put(self, val):
     if isinstance(val, ClientObjectRef):
         raise TypeError(
             "Calling 'put' on an ObjectRef is not allowed "
             "(similarly, returning an ObjectRef from a remote "
             "function is not allowed). If you really want to "
             "do this, you can wrap the ObjectRef in a list and "
             "call 'put' on it (or return it).")
     data = dumps_from_client(val, self._client_id)
     req = ray_client_pb2.PutRequest(data=data)
     resp = self.data_client.PutObject(req)
     return ClientObjectRef(resp.id)
Exemplo n.º 2
0
 def get_actor(self,
               name: str,
               namespace: Optional[str] = None) -> ClientActorHandle:
     task = ray_client_pb2.ClientTask()
     task.type = ray_client_pb2.ClientTask.NAMED_ACTOR
     task.name = name
     task.namespace = namespace or ""
     # Populate task.data with empty args and kwargs
     task.data = dumps_from_client(([], {}), self._client_id)
     futures = self._call_schedule_for_task(task, 1)
     assert len(futures) == 1
     handle = ClientActorHandle(ClientActorRef(futures[0]))
     # `actor_ref.is_nil()` waits until the underlying ID is resolved.
     # This is needed because `get_actor` is often used to check the
     # existence of an actor.
     if handle.actor_ref.is_nil():
         raise ValueError(f"ActorID for {name} is empty")
     return handle
Exemplo n.º 3
0
 def _put(self, val, *, client_ref_id: bytes = None):
     if isinstance(val, ClientObjectRef):
         raise TypeError(
             "Calling 'put' on an ObjectRef is not allowed "
             "(similarly, returning an ObjectRef from a remote "
             "function is not allowed). If you really want to "
             "do this, you can wrap the ObjectRef in a list and "
             "call 'put' on it (or return it).")
     data = dumps_from_client(val, self._client_id)
     req = ray_client_pb2.PutRequest(data=data)
     if client_ref_id is not None:
         req.client_ref_id = client_ref_id
     resp = self.data_client.PutObject(req)
     if not resp.valid:
         try:
             raise cloudpickle.loads(resp.error)
         except pickle.UnpicklingError:
             logger.exception("Failed to deserialize {}".format(resp.error))
             raise
     return ClientObjectRef(resp.id)
Exemplo n.º 4
0
Arquivo: worker.py Projeto: alipay/ray
 def _dumps_from_client(self, val) -> bytes:
     return dumps_from_client(val, self._client_id)
Exemplo n.º 5
0
 def call_remote(self, instance, *args, **kwargs) -> List[Future]:
     task = instance._prepare_client_task()
     # data is serialized tuple of (args, kwargs)
     task.data = dumps_from_client((args, kwargs), self._client_id)
     return self._call_schedule_for_task(task, instance._num_returns())