Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core][doc] ray.get with timeout=0 will warn behavior change in future ray releases. #31140

Merged
merged 9 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion python/ray/_private/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2273,7 +2273,13 @@ def get(
object_refs: Object ref of the object to get or a list of object refs
to get.
timeout (Optional[float]): The maximum amount of time in seconds to
wait before returning.
wait before returning. Set this to None will block until the
corresponding object becomes available.
WARNING: In future ray releases ``timeout=0`` will return the object
immediately if it's available, else raise GetTimeoutError in accordance with
the above docstring. The current behavior of blocking until objects become
available of ``timeout=0`` is considered to be a bug, see
https://github.com/ray-project/ray/issues/28465.

Returns:
A Python object or a list of Python objects.
Expand All @@ -2284,6 +2290,21 @@ def get(
Exception: An exception is raised if the task that created the object
or that created one of the objects raised an exception.
"""
if timeout == 0:
if os.environ.get("RAY_WARN_RAY_GET_TIMEOUT_ZERO", "1") == "1":
import warnings

warnings.warn(
(
"Please use timeout=None if you expect ray.get() to block. "
"Setting timeout=0 in future ray releases will raise "
"GetTimeoutError if the objects references are not available. "
"You could suppress this warning by setting "
"RAY_WARN_RAY_GET_TIMEOUT_ZERO=0."
),
UserWarning,
)

worker = global_worker
worker.check_connected()

Expand Down
15 changes: 15 additions & 0 deletions python/ray/tests/test_advanced_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,21 @@ def test():
assert cluster_resources == {}


def test_ray_get_timeout_zero(monkeypatch):
# Check that ray.get(timeout=0) raises warnings on change of behavior.
# Removed when https://github.com/ray-project/ray/issues/28465 is resolved.
with pytest.warns(UserWarning):
ray.get(ray.put(1), timeout=0)

with monkeypatch.context() as m:
m.setenv("RAY_WARN_RAY_GET_TIMEOUT_ZERO", "0")
import warnings

with warnings.catch_warnings():
warnings.simplefilter("error")
ray.get(ray.put(1), timeout=0)


if __name__ == "__main__":
if os.environ.get("PARALLEL_CI"):
sys.exit(pytest.main(["-n", "auto", "--boxed", "-vs", __file__]))
Expand Down