示例#1
0
def connect(conn_str: str,
            secure: bool = False,
            metadata: List[Tuple[str, str]] = None,
            connection_retries: int = 3,
            job_config: JobConfig = None,
            namespace: str = None,
            *,
            ignore_version: bool = False) -> Dict[str, Any]:
    if ray.is_connected():
        raise RuntimeError("Ray Client is already connected. "
                           "Maybe you called ray.util.connect twice by "
                           "accident?")
    # Enable the same hooks that RAY_CLIENT_MODE does, as
    # calling ray.util.connect() is specifically for using client mode.
    _set_client_hook_status(True)
    _explicitly_enable_client_mode()

    # TODO(barakmich): https://github.com/ray-project/ray/issues/13274
    # for supporting things like cert_path, ca_path, etc and creating
    # the correct metadata
    return ray.connect(conn_str,
                       job_config=job_config,
                       secure=secure,
                       metadata=metadata,
                       connection_retries=connection_retries,
                       namespace=namespace,
                       ignore_version=ignore_version)
示例#2
0
 def __dir__(self) -> List[str]:
     if self._method_num_returns is not None:
         return self._method_num_returns.keys()
     if ray.is_connected():
         self._init_class_info()
         return self._method_num_returns.keys()
     return super().__dir__()
示例#3
0
def connect(
        conn_str: str,
        secure: bool = False,
        metadata: List[Tuple[str, str]] = None,
        connection_retries: int = 3,
        job_config: JobConfig = None,
        namespace: str = None,
        *,
        ignore_version: bool = False,
        _credentials: Optional[grpc.ChannelCredentials] = None,
        ray_init_kwargs: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
    if ray.is_connected():
        raise RuntimeError("Ray Client is already connected. Maybe you called "
                           'ray.init("ray://<address>") twice by accident?')

    # Enable the same hooks that RAY_CLIENT_MODE does, as calling
    # ray.init("ray://<address>") is specifically for using client mode.
    _set_client_hook_status(True)
    _explicitly_enable_client_mode()

    # TODO(barakmich): https://github.com/ray-project/ray/issues/13274
    # for supporting things like cert_path, ca_path, etc and creating
    # the correct metadata
    conn = ray.connect(
        conn_str,
        job_config=job_config,
        secure=secure,
        metadata=metadata,
        connection_retries=connection_retries,
        namespace=namespace,
        ignore_version=ignore_version,
        _credentials=_credentials,
        ray_init_kwargs=ray_init_kwargs,
    )
    return conn
示例#4
0
文件: common.py 项目: haochihlin/ray
 def __del__(self) -> None:
     if ray is None:
         # The ray API stub might be set to None when the script exits.
         # Should be safe to skip call_release in this case, since the
         # client should have already disconnected at this point.
         return
     if ray.is_connected():
         ray.call_release(self.actor_ref.id)
示例#5
0
    def __dir__(self) -> List[str]:
        if self._dir is not None:
            return self._dir
        if ray.is_connected():

            @ray.remote(num_cpus=0)
            def get_dir(x):
                return dir(x)

            self._dir = ray.get(get_dir.remote(self))
            return self._dir
        return super().__dir__()
示例#6
0
def connect(conn_str: str,
            secure: bool = False,
            metadata: List[Tuple[str, str]] = None) -> None:
    if ray.is_connected():
        raise RuntimeError("Ray Client is already connected. "
                           "Maybe you called ray.util.connect twice by "
                           "accident?")
    # Enable the same hooks that RAY_CLIENT_MODE does, as
    # calling ray.util.connect() is specifically for using client mode.
    _enable_client_hook(True)
    _explicitly_enable_client_mode()

    # TODO(barakmich): https://github.com/ray-project/ray/issues/13274
    # for supporting things like cert_path, ca_path, etc and creating
    # the correct metadata
    return ray.connect(conn_str, secure=secure, metadata=metadata)
示例#7
0
def disconnect():
    if not ray.is_connected():
        raise RuntimeError("Ray Client is currently disconnected.")
    return ray.disconnect()
示例#8
0
 def __del__(self) -> None:
     if ray.is_connected():
         ray.call_release(self.actor_ref.id)
示例#9
0
文件: common.py 项目: supatomic/ray
 def __del__(self):
     if ray.is_connected() and self.id is not None:
         ray.call_release(self.id)