mirror of
https://github.com/wassname/ray.git
synced 2026-07-03 01:09:13 +08:00
[ray_client]: first draft of documentation (#13216)
This commit is contained in:
@@ -7,8 +7,20 @@ from ray.util.placement_group import (placement_group, placement_group_table,
|
||||
remove_placement_group)
|
||||
from ray.util import rpdb as pdb
|
||||
|
||||
from ray.util.client_connect import connect, disconnect
|
||||
|
||||
__all__ = [
|
||||
"ActorPool", "disable_log_once_globally", "enable_periodic_logging",
|
||||
"iter", "log_once", "pdb", "placement_group", "placement_group_table",
|
||||
"remove_placement_group", "inspect_serializability", "collective"
|
||||
"ActorPool",
|
||||
"disable_log_once_globally",
|
||||
"enable_periodic_logging",
|
||||
"iter",
|
||||
"log_once",
|
||||
"pdb",
|
||||
"placement_group",
|
||||
"placement_group_table",
|
||||
"remove_placement_group",
|
||||
"inspect_serializability",
|
||||
"collective",
|
||||
"connect",
|
||||
"disconnect",
|
||||
]
|
||||
|
||||
@@ -75,7 +75,7 @@ class RayAPIStub:
|
||||
return getattr(self.api, key)
|
||||
|
||||
def is_connected(self) -> bool:
|
||||
return self.api is not None
|
||||
return self.client_worker is not None
|
||||
|
||||
def init(self, *args, **kwargs):
|
||||
if self._server is not None:
|
||||
|
||||
@@ -427,7 +427,7 @@ def main():
|
||||
"-p", "--port", type=int, default=50051, help="Port to bind to")
|
||||
parser.add_argument(
|
||||
"--redis-address",
|
||||
required=True,
|
||||
required=False,
|
||||
type=str,
|
||||
help="Address to use to connect to Ray")
|
||||
parser.add_argument(
|
||||
@@ -437,11 +437,15 @@ def main():
|
||||
help="Password for connecting to Redis")
|
||||
args = parser.parse_args()
|
||||
logging.basicConfig(level="INFO")
|
||||
if args.redis_password:
|
||||
ray.init(
|
||||
address=args.redis_address, _redis_password=args.redis_password)
|
||||
if args.redis_address:
|
||||
if args.redis_password:
|
||||
ray.init(
|
||||
address=args.redis_address,
|
||||
_redis_password=args.redis_password)
|
||||
else:
|
||||
ray.init(address=args.redis_address)
|
||||
else:
|
||||
ray.init(address=args.redis_address)
|
||||
ray.init()
|
||||
hostport = "%s:%d" % (args.host, args.port)
|
||||
logger.info(f"Starting Ray Client server on {hostport}")
|
||||
server = serve(hostport)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
from ray.util.client import ray
|
||||
|
||||
from ray._private.client_mode_hook import _enable_client_hook
|
||||
from ray._private.client_mode_hook import _explicitly_enable_client_mode
|
||||
|
||||
from typing import List
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def disconnect():
|
||||
if not ray.is_connected():
|
||||
raise RuntimeError("Ray Client is currently disconnected.")
|
||||
return ray.disconnect()
|
||||
Reference in New Issue
Block a user