Skip to content

Commit

Permalink
[Serve] Remove the warning for async handles in 2.0 (ray-project#27346)
Browse files Browse the repository at this point in the history
Signed-off-by: simon-mo <[email protected]>
  • Loading branch information
simon-mo committed Aug 7, 2022
1 parent e43278a commit 8882ae4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 47 deletions.
29 changes: 0 additions & 29 deletions python/ray/serve/_private/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import atexit
import logging
import random
Expand All @@ -23,9 +22,6 @@
from ray.serve.schema import ServeApplicationSchema

logger = logging.getLogger(__file__)
# Whether to issue warnings about using sync handles in async context
# or using async handle in sync context.
_WARN_SYNC_ASYNC_HANDLE_CONTEXT: bool = True


def _ensure_connected(f: Callable) -> Callable:
Expand Down Expand Up @@ -367,31 +363,6 @@ def get_handle(
if not missing_ok and deployment_name not in all_endpoints:
raise KeyError(f"Deployment '{deployment_name}' does not exist.")

try:
asyncio_loop_running = asyncio.get_event_loop().is_running()
except RuntimeError as ex:
if "There is no current event loop in thread" in str(ex):
asyncio_loop_running = False
else:
raise ex

if asyncio_loop_running and sync and _WARN_SYNC_ASYNC_HANDLE_CONTEXT:
logger.warning(
"You are retrieving a sync handle inside an asyncio loop. "
"Try getting Deployment.get_handle(.., sync=False) to get better "
"performance. Learn more at https://docs.ray.io/en/latest/serve/"
"handle-guide.html#sync-and-async-handles"
)

if not asyncio_loop_running and not sync and _WARN_SYNC_ASYNC_HANDLE_CONTEXT:
logger.warning(
"You are retrieving an async handle outside an asyncio loop. "
"You should make sure Deployment.get_handle is called inside a "
"running event loop. Or call Deployment.get_handle(.., sync=True) "
"to create sync handle. Learn more at https://docs.ray.io/en/latest/"
"serve/handle-guide.html#sync-and-async-handles"
)

if sync:
handle = RayServeSyncHandle(
self._controller,
Expand Down
25 changes: 7 additions & 18 deletions python/ray/serve/deployment_graph.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
from contextlib import contextmanager
import json

from ray.dag.class_node import ClassNode # noqa: F401
from ray.dag.function_node import FunctionNode # noqa: F401
from ray.dag.input_node import InputNode # noqa: F401
from ray.dag import DAGNode # noqa: F401
from ray.util.annotations import PublicAPI
import ray.serve._private.client


@contextmanager
def _mute_sync_handle_warnings():
ray.serve._private.client._WARN_SYNC_ASYNC_HANDLE_CONTEXT = False
yield
ray.serve._private.client._WARN_SYNC_ASYNC_HANDLE_CONTEXT = True


@PublicAPI(stability="alpha")
Expand Down Expand Up @@ -41,12 +32,10 @@ def __reduce__(self):
return RayServeDAGHandle._deserialize, (self.dag_node_json,)

def remote(self, *args, **kwargs):
# NOTE: There's nothing user can do about these warnings, we should hide it.
with _mute_sync_handle_warnings():
if self.dag_node is None:
from ray.serve._private.json_serde import dagnode_from_json

self.dag_node = json.loads(
self.dag_node_json, object_hook=dagnode_from_json
)
return self.dag_node.execute(*args, **kwargs)
if self.dag_node is None:
from ray.serve._private.json_serde import dagnode_from_json

self.dag_node = json.loads(
self.dag_node_json, object_hook=dagnode_from_json
)
return self.dag_node.execute(*args, **kwargs)

0 comments on commit 8882ae4

Please sign in to comment.