mirror of
https://github.com/vale981/ray
synced 2025-03-06 02:21:39 -05:00
[Core] Make "GetTimeoutError" a subclass of "TimeoutError" (#26771)
I am surprised by the fact that `GetTimeoutError` is not a subclass of `TimeoutError`, which is counter-intuitive and may discourage users from trying the timeout feature in `ray.get`, because you have to "guess" the correct error type. For most people, I believe the first error type in their mind would be `TimeoutError`. This PR fixes this.
This commit is contained in:
parent
8a45425e7b
commit
0063d94166
3 changed files with 7 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue