diff --git a/doc/source/ray-core/objects.rst b/doc/source/ray-core/objects.rst index c0c39b8fd..c8cb25c8d 100644 --- a/doc/source/ray-core/objects.rst +++ b/doc/source/ray-core/objects.rst @@ -69,16 +69,16 @@ If the current node's object store does not contain the object, the object is do # You can also set a timeout to return early from a ``get`` # that's blocking for too long. from ray.exceptions import GetTimeoutError + # ``GetTimeoutError`` is a subclass of ``TimeoutError``. @ray.remote - def long_running_function(): time.sleep(8) obj_ref = long_running_function.remote() try: ray.get(obj_ref, timeout=4) - except GetTimeoutError: + except GetTimeoutError: # You can capture the standard "TimeoutError" instead print("`get` timed out.") .. tabbed:: Java diff --git a/python/ray/exceptions.py b/python/ray/exceptions.py index c4668753c..5fcbfc0df 100644 --- a/python/ray/exceptions.py +++ b/python/ray/exceptions.py @@ -547,7 +547,7 @@ class ObjectReconstructionFailedLineageEvictedError(ObjectLostError): @PublicAPI -class GetTimeoutError(RayError): +class GetTimeoutError(RayError, TimeoutError): """Indicates that a call to the worker timed out.""" pass diff --git a/python/ray/tests/test_basic_2.py b/python/ray/tests/test_basic_2.py index 6c20ae673..b83280fce 100644 --- a/python/ray/tests/test_basic_2.py +++ b/python/ray/tests/test_basic_2.py @@ -380,6 +380,10 @@ def test_get_with_timeout(ray_start_regular_shared): with pytest.raises(GetTimeoutError): ray.get(result_id, timeout=0.1) + assert issubclass(GetTimeoutError, TimeoutError) + with pytest.raises(TimeoutError): + ray.get(result_id, timeout=0.1) + # Check that a subsequent get() returns early. ray.get(signal.send.remote()) start = time.time()