ray.serve.handle.RayServeHandle#

class ray.serve.handle.RayServeHandle(controller_handle: ray.actor.ActorHandle, deployment_name: str, handle_options: Optional[ray.serve.handle.HandleOptions] = None, *, _router: Optional[ray.serve._private.router.Router] = None, _internal_pickled_http_request: bool = False)[source]#

Bases: object

A handle to a service deployment.

Invoking this deployment with .remote is equivalent to pinging an HTTP deployment.

Example

>>> import ray
>>> serve_client = ... 
>>> handle = serve_client.get_handle("my_deployment") 
>>> handle 
RayServeSyncHandle(deployment_name="my_deployment")
>>> my_request_content = ... 
>>> handle.remote(my_request_content) 
ObjectRef(...)
>>> ray.get(handle.remote(...)) 
# result
>>> let_it_crash_request = ... 
>>> ray.get(handle.remote(let_it_crash_request)) 
# raises RayTaskError Exception
>>> async_handle = serve_client.get_handle( 
...     "my_deployment", sync=False)
>>> async_handle  
RayServeHandle(deployment="my_deployment")
>>> await async_handle.remote(my_request_content) 
ObjectRef(...)
>>> ray.get(await async_handle.remote(...)) 
# result
>>> ray.get( 
...     await async_handle.remote(let_it_crash_request)
... )
# raises RayTaskError Exception

PublicAPI (beta): This API is in beta and may change before becoming stable.

Methods

options(*[, method_name])

Set options for this handle.

remote(*args, **kwargs)

Issue an asynchronous request to the deployment.

Attributes

is_polling

Whether this handle is actively polling for replica updates.

is_same_loop

Whether the caller's asyncio loop is the same loop for handle.