From fa5774a51b9f94766aae06bab7c724d876195de6 Mon Sep 17 00:00:00 2001 From: simon-mo Date: Fri, 21 Feb 2020 11:47:34 -0800 Subject: [PATCH 1/5] Change error to one time warning --- python/ray/worker.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/python/ray/worker.py b/python/ray/worker.py index b1547e7c55ca8..bd4acf8eae8d6 100644 --- a/python/ray/worker.py +++ b/python/ray/worker.py @@ -1445,6 +1445,10 @@ def show_in_webui(message, key="", dtype="text"): worker.core_worker.set_webui_display(key.encode(), message_encoded) +# Global varaible to make sure we only send out the warning once +blocking_get_inside_async_warned = False + + def get(object_ids, timeout=None): """Get a remote object or a list of remote objects from the object store. @@ -1454,7 +1458,7 @@ def get(object_ids, timeout=None): object has been created). If object_ids is a list, then the objects corresponding to each object in the list will be returned. - This method will error will error if it's running inside async context, + This method issue a warning if it's running inside async context, you can use ``await object_id`` instead of ``ray.get(object_id)``. For a list of object ids, you can use ``await asyncio.gather(*object_ids)``. @@ -1479,9 +1483,12 @@ def get(object_ids, timeout=None): if hasattr( worker, "core_worker") and worker.core_worker.current_actor_is_asyncio(): - raise RayError("Using blocking ray.get inside async actor. " - "This blocks the event loop. Please " - "use `await` on object id with asyncio.gather.") + global blocking_get_inside_async_warned + if not blocking_get_inside_async_warned: + logger.warning("Using blocking ray.get inside async actor. " + "This blocks the event loop. Please " + "use `await` on object id with asyncio.gather.") + blocking_get_inside_async_warned = True with profiling.profile("ray.get"): is_individual_id = isinstance(object_ids, ray.ObjectID) @@ -1547,6 +1554,10 @@ def put(value, weakref=False): return object_id +# Global varaible to make sure we only send out the warning once +blocking_wait_inside_async_warned = False + + def wait(object_ids, num_returns=1, timeout=None): """Return a list of IDs that are ready and a list of IDs that are not. @@ -1565,8 +1576,9 @@ def wait(object_ids, num_returns=1, timeout=None): precede B in the ready list. This also holds true if A and B are both in the remaining list. - This method will error if it's running inside an async context. Instead of - ``ray.wait(object_ids)``, you can use ``await asyncio.wait(object_ids)``. + This method will issue a warning if it's running inside an async context. + Instead of ``ray.wait(object_ids)``, you can use + ``await asyncio.wait(object_ids)``. Args: object_ids (List[ObjectID]): List of object IDs for objects that may or @@ -1584,9 +1596,12 @@ def wait(object_ids, num_returns=1, timeout=None): if hasattr(worker, "core_worker") and worker.core_worker.current_actor_is_asyncio( ) and timeout != 0: - raise RayError("Using blocking ray.wait inside async method. " - "This blocks the event loop. Please use `await` " - "on object id with asyncio.wait. ") + global blocking_wait_inside_async_warned + if not blocking_wait_inside_async_warned: + logger.warning("Using blocking ray.wait inside async method. " + "This blocks the event loop. Please use `await` " + "on object id with asyncio.wait. ") + blocking_wait_inside_async_warned = True if isinstance(object_ids, ObjectID): raise TypeError( From ecae266a9a00c2c2618f06485bbc343787cd8d5c Mon Sep 17 00:00:00 2001 From: simon-mo Date: Fri, 21 Feb 2020 11:49:11 -0800 Subject: [PATCH 2/5] Grammar --- python/ray/worker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ray/worker.py b/python/ray/worker.py index bd4acf8eae8d6..1de84bcc08bc0 100644 --- a/python/ray/worker.py +++ b/python/ray/worker.py @@ -1458,7 +1458,7 @@ def get(object_ids, timeout=None): object has been created). If object_ids is a list, then the objects corresponding to each object in the list will be returned. - This method issue a warning if it's running inside async context, + This method will issue a warning if it's running inside async context, you can use ``await object_id`` instead of ``ray.get(object_id)``. For a list of object ids, you can use ``await asyncio.gather(*object_ids)``. From e197db09284ff1723ec2a2d05fffb1b64cae6b3e Mon Sep 17 00:00:00 2001 From: simon-mo Date: Fri, 21 Feb 2020 11:49:30 -0800 Subject: [PATCH 3/5] Lint --- python/ray/worker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/ray/worker.py b/python/ray/worker.py index 1de84bcc08bc0..74f94d7c424b7 100644 --- a/python/ray/worker.py +++ b/python/ray/worker.py @@ -1576,8 +1576,8 @@ def wait(object_ids, num_returns=1, timeout=None): precede B in the ready list. This also holds true if A and B are both in the remaining list. - This method will issue a warning if it's running inside an async context. - Instead of ``ray.wait(object_ids)``, you can use + This method will issue a warning if it's running inside an async context. + Instead of ``ray.wait(object_ids)``, you can use ``await asyncio.wait(object_ids)``. Args: From 77d8d103d4c23a80d5e924698ae2c26462ad0d18 Mon Sep 17 00:00:00 2001 From: Simon Mo Date: Fri, 21 Feb 2020 17:09:58 -0800 Subject: [PATCH 4/5] Apply suggestions from code review Co-Authored-By: Edward Oakes --- python/ray/worker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/ray/worker.py b/python/ray/worker.py index 74f94d7c424b7..e256026c5bdb6 100644 --- a/python/ray/worker.py +++ b/python/ray/worker.py @@ -1487,7 +1487,7 @@ def get(object_ids, timeout=None): if not blocking_get_inside_async_warned: logger.warning("Using blocking ray.get inside async actor. " "This blocks the event loop. Please " - "use `await` on object id with asyncio.gather.") + "use `await` on object id with asyncio.gather if you want to yield execution to the event loop instead.") blocking_get_inside_async_warned = True with profiling.profile("ray.get"): @@ -1554,7 +1554,7 @@ def put(value, weakref=False): return object_id -# Global varaible to make sure we only send out the warning once +# Global variable to make sure we only send out the warning once. blocking_wait_inside_async_warned = False From 080e31938d4fecaadab6aeb1fdf6ce87f44144a6 Mon Sep 17 00:00:00 2001 From: simon-mo Date: Fri, 28 Feb 2020 10:58:32 -0800 Subject: [PATCH 5/5] Lint --- python/ray/worker.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/ray/worker.py b/python/ray/worker.py index e256026c5bdb6..993da822db5b7 100644 --- a/python/ray/worker.py +++ b/python/ray/worker.py @@ -1486,8 +1486,9 @@ def get(object_ids, timeout=None): global blocking_get_inside_async_warned if not blocking_get_inside_async_warned: logger.warning("Using blocking ray.get inside async actor. " - "This blocks the event loop. Please " - "use `await` on object id with asyncio.gather if you want to yield execution to the event loop instead.") + "This blocks the event loop. Please use `await` " + "on object id with asyncio.gather if you want to " + "yield execution to the event loop instead.") blocking_get_inside_async_warned = True with profiling.profile("ray.get"):