mirror of
https://github.com/wassname/ray.git
synced 2026-07-19 11:27:32 +08:00
[api] Second round of 1.0 API changes: exceptions, num_return_vals (#10377)
This commit is contained in:
@@ -54,7 +54,7 @@ Any method of the actor can return multiple object refs with the ``ray.method``
|
||||
@ray.remote
|
||||
class Foo(object):
|
||||
|
||||
@ray.method(num_return_vals=2)
|
||||
@ray.method(num_returns=2)
|
||||
def bar(self):
|
||||
return 1, 2
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ And vary the number of return values for tasks (and actor methods too):
|
||||
def f(n):
|
||||
return list(range(n))
|
||||
|
||||
id1, id2 = f.options(num_return_vals=2).remote(2)
|
||||
id1, id2 = f.options(num_returns=2).remote(2)
|
||||
assert ray.get(id1) == 0
|
||||
assert ray.get(id2) == 1
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ You can experiment with this behavior by running the following code.
|
||||
# exception.
|
||||
ray.get(potentially_fail.remote(0.5))
|
||||
print('SUCCESS')
|
||||
except ray.exceptions.RayWorkerError:
|
||||
except ray.exceptions.WorkerCrashedError:
|
||||
print('FAILURE')
|
||||
|
||||
.. _actor-fault-tolerance:
|
||||
@@ -172,7 +172,7 @@ Task outputs over a configurable threshold (default 100KB) may be stored in
|
||||
Ray's distributed object store. Thus, a node failure can cause the loss of a
|
||||
task output. If this occurs, Ray will automatically attempt to recover the
|
||||
value by looking for copies of the same object on other nodes. If there are no
|
||||
other copies left, an ``UnreconstructableError`` will be raised.
|
||||
other copies left, an ``ObjectLostError`` will be raised.
|
||||
|
||||
When there are no copies of an object left, Ray also provides an option to
|
||||
automatically recover the value by re-executing the task that created the
|
||||
|
||||
@@ -253,7 +253,7 @@ Multiple returns
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@ray.remote(num_return_vals=3)
|
||||
@ray.remote(num_returns=3)
|
||||
def return_multiple():
|
||||
return 1, 2, 3
|
||||
|
||||
@@ -341,7 +341,7 @@ If the current node's object store does not contain the object, the object is do
|
||||
assert ray.get([ray.put(i) for i in range(3)]) == [0, 1, 2]
|
||||
|
||||
# You can also set a timeout to return early from a ``get`` that's blocking for too long.
|
||||
from ray.exceptions import RayTimeoutError
|
||||
from ray.exceptions import GetTimeoutError
|
||||
|
||||
@ray.remote
|
||||
def long_running_function()
|
||||
@@ -350,7 +350,7 @@ If the current node's object store does not contain the object, the object is do
|
||||
obj_ref = long_running_function.remote()
|
||||
try:
|
||||
ray.get(obj_ref, timeout=4)
|
||||
except RayTimeoutError:
|
||||
except GetTimeoutError:
|
||||
print("`get` timed out.")
|
||||
|
||||
.. group-tab:: Java
|
||||
|
||||
Reference in New Issue
Block a user